Monday, December 27, 2010

Changing the positive & negetive softkeys




Qt menu bar has two menu items, as you would have seen by default left side of the key is “Options” and the right side is “Exit”.
Today we shall see how to change the text of it.
The left key is “Positive Soft key” & the right key is “Negative soft key”. We need to create an action with the positive and negative soft key role and insert to the window, so the keys will get changed.
Ex: For positive soft key:(Left side key)

QAction* Newkey = new QAction("New", this);
Newkey->setSoftKeyRole(QAction::PositiveSoftKey);
this->addAction(Newkey);


Negative soft key: (Right side key)
QAction* close = new QAction("close", this);
close->setSoftKeyRole(QAction::NegativeSoftKey);
this->addAction(close);


Here is the sample code, just put these files in a sample application and run for the results

.cpp file

#include "QT_Softkeys.h"
#include <qmessagebox.h>

QT_Softkeys::QT_Softkeys(QWidget *parent)
    : QMainWindow(parent)
{
        //ui.setupUi(this);
        
    
        QAction* Newkey = new QAction("New", this);
        Newkey->setSoftKeyRole(QAction::PositiveSoftKey);
        this->addAction(Newkey);
        
        QAction* close = new QAction("close", this);
        close->setSoftKeyRole(QAction::NegativeSoftKey);
        connect(close,SIGNAL(triggered()),this,SLOT(closeClickked()));
        this->addAction(close);
                       
        
}

QT_Softkeys::~QT_Softkeys()
{

}

void QT_Softkeys::closeClickked()
        {
        QMessageBox::information(this,"Hi","Hi we r closing");
        QApplication::quit();
        }


Header file

#ifndef QT_SOFTKEYS_H
#define QT_SOFTKEYS_H

#include <QtGui/QMainWindow>
#include "ui_QT_Softkeys.h"

class QT_Softkeys : public QMainWindow
{
    Q_OBJECT

public:
        QT_Softkeys(QWidget *parent = 0);
    ~QT_Softkeys();
    
    public slots:
    void closeClickked();

private:
    Ui::QT_Softkeys ui;
};

#endif // QT_SOFTKEYS_H


Sunday, October 10, 2010

Localization in QT




Some instructions need to be followed in performing localization in Qt

Instructions:

1)Add tr macro for all the QString assignment.
2)Assigning the string to Non Qt objects pointer use QT_TRANSLATE_NOOP macro.
3)Assigning the string to Non Qt objects in some function use QT_NOOP macro.

Here are some samples,which shows how to add strings for Localization compatible.

Syntax to be used for global char*.

const char* TestStr = QT_TRANSLATE_NOOP("StringList","Welcome To Qt");
QPushButton *pushBtn = new QPushButton(qApp->translate("StringList",TestStr));

For Qstring Objects.

QString UIstr = QObject::tr("Qt is a Framework");
QPushButton *pushBtn = new QPushButton(tr(UIstr));

For local char*.

const char * text = QT_TR_NOOP("Qt framework rocks");
QPushButton *pushBtn = new QPushButton(tr(text));


Steps needs to be followed in generation and usage of localized file in application.
1)Add the TRANSLATION Macro in the .pro file and save.

example:
TRANSLATIONS += superapp_fr.ts\
TRANSLATIONS += superapp_jp.ts

like this, add all possible language translation file you need.
2)Use lupdate command in Qt Command prompt to generate the .ts file and .ts file will be in your project folder.

 
3)  Open the .ts file in Qt linguist tool and add the mapping strings.   
     Launch Qt Linguist From Start Menu
    

 Adding mapping strings to the English equivalent strings.


4)Similar to step2 use lrelease to generate the .qm file and .qm file will be in your project folder.

5)Copy .qm file and place it in desired location and load it on launching the application.


Here how the loading part of code looks.

QTranslator translator;
translator.load("c:\\Data\\MyStrings_fr");
a.installTranslator(&translator);




Sunday, August 29, 2010

Smart installer for The Symbian applications.




Smart installer for The Symbian applications.

This post describes in brief what smart installer is, and why it is essential for the Symbian applications.

How will you run the Symbian applications in a phone which doesn’t have Qt SDK installed?
To overcome this problem Nokia has provided the simple solution i.e the Smart installer.

Smart installer is pre embedded in your .sis file, when you download an application from the OVI store, first the smart installer checks, weather the Qt is installed in your phone, if not it will download the latest Qt from the Nokia server and install to the phone. application gets installed in the post installation phase. This is how it works.

Please Note: If you are using the Carbide editor for Symbian application development, then smart installer doesn’t work. To make smart installer you need to have the Nokia QT SDK only.

Requirements:
Nokia QT SDK. Download link
Certificates for the Signed .sis file.


How to make the Signed smart installer for the OVI store.


1)    Launch Nokia Qt SDK command prompt.
       

2)    Go to application Directory,
3)    qmake
4)    make release-gcce

To sign the application, you can put the certificates in the current directory or you can refer it from the other drive also. If you are referring from the other drive please mention the Path properly.

 5) make sis QT_SIS_CERTIFICATE=publisherid.cer  QT_SIS_KEY=publisherid.key
 This will generate  signed sis file


 6) make installer_sis QT_SIS_CERTIFICATE=publisherid.cer  QT_SIS_KEY=publisherid.key
 This will generate  smart installer signed sis file.





Follow up these steps for the self self-signed Smart Installer package.

1)qmake

2)make release-gcce
Simple SIS file.

3)make installer_sis
Smart installer SIS file

more information about Qt smart installer can be found here
http://doc.qt.nokia.com/smart-installer-1.0/index.html