Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 36
Registered: ‎02-06-2011
My Device: bold 9900
My Carrier: Vodacom

QML how to show and hide the virtual keyboard

Im using javascript with my QML application. I want to show and hide the virtual keyboard within a javascript function. Does anyone know how to do this?

 

Alternatively if you can explain in detail how to do this in c++. My preference is javascript as I am not to strong with c++.

 

I've noticed in the include files there is a virtualkeyboard.h file which has  virtualkeboard_show() and virtualkeboard_hide() functions. How do I call these functions from qml/javascript?

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: QML how to show and hide the virtual keyboard

Keyboard.h

/*
 * Keyboard.h
 *
 *  Created on: 20 Mar 2013
 *      Author: Stephen
 */

#ifndef KEYBOARD_H_
#define KEYBOARD_H_

#include <QObject>

class Keyboard: public QObject {

	Q_OBJECT

public:
	Keyboard();
	virtual ~Keyboard();

	Q_INVOKABLE void show();
	Q_INVOKABLE void hide();

};

#endif /* KEYBOARD_H_ */

 

Keyboard.cpp

/*
 * Keyboard.cpp
 *
 *  Created on: 20 Mar 2013
 *      Author: Stephen
 */

#include "Keyboard.h"

#include <bps/virtualkeyboard.h>

Keyboard::Keyboard() {
	// TODO Auto-generated constructor stub

}

Keyboard::~Keyboard() {
	// TODO Auto-generated destructor stub
}

void Keyboard::show() {
	virtualkeyboard_show();
}

void Keyboard::hide() {
	virtualkeyboard_hide();
}

 applicationui.cpp

#include "Keyboard.h"

ApplicationUI::ApplicationUI(bb::cascades::Application *app)
	: QObject(app)

{

    qmlRegisterType<Keyboard>("custom.lib", 1, 0, "Keyboard");

    [ ... ]
}

 Test.qml

import bb.cascades 1.0
import custom.lib 1.0

RecipePage {
    property bool keyb: false

    RecipeContainer {
 
        Button {
            text: "Show/Hide Keyboard"
            onClicked: {
                keyb = !keyb;
                if (keyb)
                    key.show();
                else
                    key.hide();
            }
        }
        attachedObjects: [
            Keyboard { id: key }
        ]
    }
}

 


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 36
Registered: ‎02-06-2011
My Device: bold 9900
My Carrier: Vodacom

Re: QML how to show and hide the virtual keyboard

Ive implemented the solution into my project. In momentics there are no errors indicated in the files. However when I build and deplay I get an error. The console logs are as follow

 

21:24:24 **** Incremental Build of configuration Device-Debug for project TypeTutorial ****
make -j2 Device-Debug
make -C .//translations -f Makefile update
make[1]: Entering directory `C:/Users/fbrown.MERSETA/ndk-10.2-workspace/TypeTutorial/translations'
D:/bbndk/host_10_2_0_1/win32/x86/usr/bin/lupdate TypeTutorial.pro
Updating 'TypeTutorial.ts'...
Found 0 source text(s) (0 new and 0 already existing)
make[1]: Leaving directory `C:/Users/fbrown.MERSETA/ndk-10.2-workspace/TypeTutorial/translations'
make -C .//translations -f Makefile release
make[1]: Entering directory `C:/Users/fbrown.MERSETA/ndk-10.2-workspace/TypeTutorial/translations'
D:/bbndk/host_10_2_0_1/win32/x86/usr/bin/lrelease TypeTutorial.pro
Updating 'C:/Users/fbrown.MERSETA/ndk-10.2-workspace/TypeTutorial/translations/TypeTutorial.qm'...
Generated 0 translation(s) (0 finished and 0 unfinished)
make[1]: Leaving directory `C:/Users/fbrown.MERSETA/ndk-10.2-workspace/TypeTutorial/translations'
make -C ./arm -f Makefile debug
make[1]: Entering directory `C:/Users/fbrown.MERSETA/ndk-10.2-workspace/TypeTutorial/arm'
make -f Makefile.Debug
make[2]: Entering directory `C:/Users/fbrown.MERSETA/ndk-10.2-workspace/TypeTutorial/arm'
qcc -Vgcc_ntoarmv7le -lang-c++ -Wl,-rpath-link,D:/bbndk/target_10_2_0_339/qnx6/armle-v7/lib -Wl,-rpath-link,D:/bbndk/target_10_2_0_339/qnx6/armle-v7/usr/lib -Wl,-rpath-link,D:/bbndk/target_10_2_0_339/qnx6/armle-v7/usr/lib/qt4/lib -o o.le-v7-g/TypeTutorial o.le-v7-g/.obj/applicationui.o o.le-v7-g/.obj/main.o o.le-v7-g/.obj/moc_applicationui.o -LD:/bbndk/target_10_2_0_339/qnx6/armle-v7/lib -LD:/bbndk/target_10_2_0_339/qnx6/armle-v7/usr/lib -LD:/bbndk/target_10_2_0_339/qnx6/armle-v7/usr/lib/qt4/lib -LD:/bbndk/target_10_2_0_339/qnx6//usr/lib/qt4/lib -lbbcascades -lQtDeclarative -lQtScript -lQtSvg -lQtSql -lsqlite3 -lz -lQtXmlPatterns -lQtGui -lQtNetwork -lsocket -lQtCore -lm -lbps
o.le-v7-g/.obj/applicationui.o: In function `int qmlRegisterType<Keyboard>(char const*, int, int, char const*)':
d:/bbndk/target_10_2_0_339/qnx6/usr/include/qt4/QtDeclarative/qdeclarative.h:162: undefined reference to `Keyboard::staticMetaObject'
d:/bbndk/target_10_2_0_339/qnx6/usr/include/qt4/QtDeclarative/qdeclarative.h:162: undefined reference to `Keyboard::staticMetaObject'
d:/bbndk/target_10_2_0_339/qnx6/usr/include/qt4/QtDeclarative/qdeclarative.h:188: undefined reference to `Keyboard::staticMetaObject'
d:/bbndk/target_10_2_0_339/qnx6/usr/include/qt4/QtDeclarative/qdeclarative.h:188: undefined reference to `Keyboard::staticMetaObject'
o.le-v7-g/.obj/applicationui.o: In function `QDeclarativeElement':
d:/bbndk/target_10_2_0_339/qnx6/usr/include/qt4/QtDeclarative/qdeclarativeprivate.h:87: undefined reference to `Keyboard::Keyboard()'
o.le-v7-g/.obj/applicationui.o:smileysad:.rodata._ZTVN19QDeclarativePrivate19QDeclarativeElementI8KeyboardEE[_ZTVN19QDeclarativePrivate19QDeclarativeElementI8KeyboardEE]+0x8): undefined reference to `Keyboard::metaObject() const'
o.le-v7-g/.obj/applicationui.o:smileysad:.rodata._ZTVN19QDeclarativePrivate19QDeclarativeElementI8KeyboardEE[_ZTVN19QDeclarativePrivate19QDeclarativeElementI8KeyboardEE]+0xc): undefined reference to `Keyboard::qt_metacast(char const*)'
o.le-v7-g/.obj/applicationui.o:smileysad:.rodata._ZTVN19QDeclarativePrivate19QDeclarativeElementI8KeyboardEE[_ZTVN19QDeclarativePrivate19QDeclarativeElementI8KeyboardEE]+0x10): undefined reference to `Keyboard::qt_metacall(QMetaObject::Call, int, void**)'
o.le-v7-g/.obj/applicationui.o:smileysad:.rodata._ZTIN19QDeclarativePrivate19QDeclarativeElementI8KeyboardEE[_ZTIN19QDeclarativePrivate19QDeclarativeElementI8KeyboardEE]+0x8): undefined reference to `typeinfo for Keyboard'
make[2]: Leaving directory `C:/Users/fbrown.MERSETA/ndk-10.2-workspace/TypeTutorial/arm'
make[1]: Leaving directory `C:/Users/fbrown.MERSETA/ndk-10.2-workspace/TypeTutorial/arm'
o.le-v7-g/.obj/applicationui.o: In function `~QDeclarativeElement':
d:/bbndk/target_10_2_0_339/qnx6/usr/include/qt4/QtDeclarative/qdeclarativeprivate.h:91: undefined reference to `Keyboard::~Keyboard()'
d:/bbndk/target_10_2_0_339/qnx6/usr/include/qt4/QtDeclarative/qdeclarativeprivate.h:91: undefined reference to `Keyboard::~Keyboard()'
cc: D:/bbndk/host_10_2_0_1/win32/x86/usr/bin/ntoarm-ld caught signal 1
make[2]: *** [o.le-v7-g/TypeTutorial] Error 1
make[1]: *** [debug] Error 2
make: *** [Device-Debug] Error 2

21:24:27 Build Finished (took 2s.985ms)

 

New Developer
Posts: 19
Registered: ‎12-16-2013
My Device: bb Z10 / STL100-1
My Carrier: operotor

Re: QML how to show and hide the virtual keyboard

I have been rying to imolement your virtual keyboard style but havent managed to do it so far.

 

when I touch/tap the text field at first time my keyboard appears.
then without touching any other control I touch/tap the same textfield the deafult keyboard appears.(I realize this accidentally.)  the OS might take the ownership somehow  at second time.
by the way I put the keyboard visible function in to onFocusedChanged signal/slot in qml. migth it be the problem ?
 
it must be some way doable since the calculator application of bb's own has the same style textbox.
 
thanks in advance.
 
 
 
here is my code like yours.
 
*
 * Keyboard.hpp
 *
 *  Created on: 30 Kas 2014
 *      Author: dogan
 */

#ifndef KEYBOARD_HPP_
#define KEYBOARD_HPP_

#include <QObject>
#include <bps/virtualkeyboard.h>


class Keyboard: public QObject
{
		Q_OBJECT

public:
	Keyboard();
	virtual ~Keyboard();

	virtualkeyboard_layout_t my_keyboard ;
	virtualkeyboard_enter_t  my_enter_key;
	Q_INVOKABLE void show();
	Q_INVOKABLE void hide();




};

#endif /* KEYBOARD_HPP_ */

 

/*
 * Keyboard.cpp
 *
 *  Created on: 30 Kas 2014
 *      Author: dogan
 */

#include <src/Keyboard.hpp>

Keyboard::Keyboard()
{

   my_keyboard = VIRTUALKEYBOARD_LAYOUT_NUMBER;
   my_enter_key = VIRTUALKEYBOARD_ENTER_DEFAULT;


}

Keyboard::~Keyboard()
{
	// TODO Auto-generated destructor stub
}

void Keyboard::show()
{
	virtualkeyboard_change_options(my_keyboard,my_enter_key);
	virtualkeyboard_show();
}

void Keyboard::hide()
{
	virtualkeyboard_hide();
}

 

.......
......
......CustomListItem
                                                {
                                                    
                                                    id:cli_currency    
                                                    dividerVisible: true
                                                    highlightAppearance: HighlightAppearance.Frame
                                                    Container 
                                                            {
                                                                Label 
                                                                {
                                                                    text: ListItemData.title_tr
                                                                }
                                                                TextField {
                                                                         id: tf
                                                                         property bool keyb: false
                                                                         input {
                                                                             flags: TextInputFlag.PredictionOff |
                                                                             TextInputFlag.AutoCorrectionOff 
                                                                            
                                                                         }
                                                            
                                                                onFocusedChanged: {                                                               
                                                                        
                                                                   
                                                                                cli_currency.ListItem.view.display_kb();                                                                     
                                                                        
                                                                                                                                
                                                                             }
                                                                
                              

                                  
                                }
                            }

                        }

                    }

                ]

                function display_kb() {

                    key.show();
                }
                
                
                
                
            

            }

        }

        attachedObjects: [
            Keyboard {
                id: key
            }

        ]
.......
....

 

 
 

 

Developer
Posts: 206
Registered: ‎04-08-2013
My Device: Z10
My Carrier: Virgin Canada

Re: QML how to show and hide the virtual keyboard

Add this to your .pro file :

LIBS += -lbb

New Developer
Posts: 19
Registered: ‎12-16-2013
My Device: bb Z10 / STL100-1
My Carrier: operotor

Re: QML how to show and hide the virtual keyboard

that library is already there.