lunes, 24 de octubre de 2011

Translations in Qt

I want to talk about a great feature in Qt, translations! I'm sure everyone have used a translated Software, as a Developer I was thinking how all that work, but I found how easy was to do it using Qt and I will explain it now.

First you need to add a line to your .pro indicating all translation you want, like this:

TRANSLATIONS = OrderMyPhotos_en.ts

Then you need to run the tool lupdate with your project file as a parameter.

lupdate project.pro

That generates the file OrderMyPhotos_en.ts

You have to open that using Qt Linguistic and start to translate, once you are done you have to run lrelease with your translated file

lrelease OrderMyPhotos_en.ts

That will generate OrderMyPhotos_en.qm

In order to use that you just have to do

QTranslator translator;
translator.load("OrderMyPhotos_en");
a.installTranslator(&translator);

And that's it, 

domingo, 16 de octubre de 2011

QSQL with SQLite

I've been trying to write a program that connects to a MySQL DB and a SQLite (I didn't found any script that converts a MySQL dump into SQLite, if you know one please let me know) In this post I just want to talk a little bit about the great QSQL

Using Qt you can write an app that connects to any of the most used DBMS like Oracle, MySQL, PostgreSQL, SQLite, and many others..The great thing about it it's that you define the database and if later you want to change to another one you can do it (that's great about the SQL standard).

I had a working example of an application that connects to a DB, it was using MySQL trough ODBC, and now with a little adjustment it uses QSQLite

    bd = QSqlDatabase::addDatabase( "QODBC" );
    bd = QSqlDatabase::addDatabase( "QSQLITE" );
 
at first I had to change the connection to QSQLITE, also the name of the database needs to
be updated 

        bd.setDatabaseName("DRIVER={MySQL ODBC 5.1 Driver};DATABASE="+nombreBD+";SERVER="+ubicacionBD);
        bd.setDatabaseName("ccomputo.sqlite");
 
With only those adjusments my application keeps working as it should..

martes, 4 de octubre de 2011

DownloadCounter - Almost 20,000

Almost 20,000 downloads for download counter, this show how a simple yet useful application can be downloaded many times.


miércoles, 21 de septiembre de 2011

Extras-Testing


I Finally got the link to promote my package, the description was missing so even the time was enough the link didn't showed up until today that I fixed the description, so DownloadCounter is in Extras Testing now :D


How to know the SQL Drivers available

In order to comunicate with a database in Qt you need the propper driver, if you want to know what drivers are available for you, you can exec this:

qDebug()<< "Availables drivers are: \n"+QSqlDatabase::drivers().join(" \n ");



Of course you need qDebug, QSqlDatabase and QtSQL in your headers.

Qt SQLite 1 - Initialize and Connect

In order to connect Qt and SQLite you have to compile the SQLite drivers (in other entry I'll talk about it)

You need to include in you headers

#include <QtSql>
#include <QSqlDatabase>
 
Then in order to initialize the DB you have to give
the driver's name to addDatabse, in this case the driver's name is
"QSQLITE"
void Queries::initDB(){
    db = QSqlDatabase::addDatabase( "QSQLITE" );
    sql = QSqlQuery  (db);
}
Then to connect and query the database you have to do something like this

bool Queries::connectDB(){
    db.setDatabaseName("db.sqlite");


    if (!db.isValid()){
       QMessageBox::critical(0,"Conecction unsuccesful" 
                              ,"<b>Problems</b>:"+db.lastError().text(),
                              QMessageBox::Ok);
        exit(0);

    }
    if (!db.open()){
        QMessageBox::critical(0,"Not connected",
                              "<b>Problems</b>: The database does not exist",
                              QMessageBox::Ok);
        return false;
    }else{

        sql.clear();
        QString strSql = "CREATE  TABLE 
                          IF NOT EXISTS \"main\".\"Users\" (\"user_id\"  
                          INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL , \"user\" 
                          CHAR NOT NULL , \"password\" CHAR NOT NULL )";
        sql.prepare(strSql);
        if( !sql.exec() ){
            showError(sql.lastError().text());
            exit(0);
        }else{
            strSql = "INSERT INTO Users (user,password) VALUES ('test','test')";
                    sql.prepare(strSql);
                    if( !sql.exec() )
                        showError(sql.lastError().text());
                    else{
                        if (sql.first())
                            {
                                qDebug() << sql.value(0).toString();
                            }
                    }

        }

        return true;
    }
}

martes, 13 de septiembre de 2011

Maemo bugtracker

Uno de los requisitos para alcanzar estar en los repositorios Extras es tener un link a donde pueden registrar bugs encontrados en tu programa, para realizar esto podemos solicitar un nuevo item en el bugzilla o si es una aplicación pequeña podemos dar un correo electrónico, para hacer eso se debe modificar el archivo control y agregarle una linea como la siguiente..

XSBC-Bugtracker: mailto:yourname@example.com
 
Help me! I wan't to be in Extras repository!