Tag Archives: linux

Macbuntu makes your linux mac-alike

19 Nov

What I like mac the most is the FONT, though Windows has a default well-enough, yet compared to MacOSX, is still looks not that good.

There’s a little bug in this transformation back, mainly focused on the textbox control, yet since it is well-enough, we should expect the next version.

Oh, btw, I am using Linux Mint 10. It suits pretty well.

Make Qt applications work with Firebird database.

23 Aug

NB:If you see this post and you like it, please follow https://rongsheng007.wordpress.com. Thx.

In the last post, we have already figure out how to connect to the firebird database in Linux/UNIX environment. In this post, I will use application built in Qt framework to connect the firebird database and do simply task.

To allowing Qt applications connect to the firebird database, we need some tools, here I introduce the IBPP project. IBPP stands for InterBase Plus Plus. IBPP is a client interface written by a group of people which provide connectivity with Interbase database system. Firebird, as is described in previous post, derived from Interbase system. Thus it is natural that IBPP interface support firebird too.

To begin, download the  IBPP source code package from: http://sourceforge.net/projects/ibpp/files/, and unpack to your desired folder. Note that this post is based on the IBPP version, all the following configurations are based on this version. You will find two folders in the destination folder where you unpacked the file into. One is “core” and the other is “tests“. (We assume that you already has a Qt project, if not, build one.) Copy all the files from the core folder to your project files location, and put them into a new core folder if you want to. Now open the project with Qt Creator, and add these files into the project.  

[Note that, if you need to install g++ to compile the project. Qt Creator doesn’t seem to provide interfaces to allow user to switch the compiler, be aware of this. OR I haven’t found it yet??]

The first job is to add one line to every IBPP file. (or maybe you have a better idea? I don’t know coz i do this job pure manually…)

What you need to add is:

#include<string.h>    OR   #include<string>

This is very tricky isn’t it? I believed that the dev-group owns their special tool to do the job before compiling…

Okay, after the job is done, we need to configure the project environment. We are using Linux operating system, but you can configure the Qt creator in a similar way in UNIX or more specific: Mac.(See the file in tests folder, it  offers details)

Open the project file(.pro) in the Projects explorer, and add the following in your project file.


LIBS +=-lfbclient -lcrypt -lm -ldl -lpthread # dependancies for shared library

Now, your project file should look like this:  

Well, I believed that ALL things are set, what we need to do is to test if it really works. Open a file in your project and try the following way to connect to the database.

First of all, you need to include a header to your project file:

#include “core/ibpp.h”  (if you do not )

then we need to connect to the database using IBPP functions, as follows:

IBPP::Database ibpp = IBPP::DatabaseFactory(“”,”sys.fdb”,”SYSDBA”,”rongsheng”);

Besides simply do this two lines, add a try-catch block to check if the connection is successfully built. The exception class in IBPP is the IBPP::Exception, and the method for printing error msg out is e.ErrorMessage(), just as follows:

(to make sure the QMessageBox works, include the “QMessageBox.h” header)




catch(IBPP::Exception& e)
QMessageBox QMsgBox;

Now run this program, if you assign a blank database file, you could see a error messagebox showing up.

To connect to the database is far way from we can say that everything is done. We still need to see how to retrieve data from the database(we assume that you have already add the connection code):

IBPP::TAM itam = IBPP::amRead;     //set mode to read
IBPP::TIL itil = IBPP::ilConcurrency;  //support concurrency
IBPP::Transaction itran = IBPP::TransactionFactory(ibpp,IBPP::amRead,IBPP::ilConcurrency,IBPP::lrWait,IBPP::TFF(0));    //Initialise the transaction class which defines the transaction procedure.
itran->Start();       //start the transaction.
IBPP::Statement istat = IBPP::StatementFactory(ibpp,itran);   //The class which contains the SQL statement to be executed.
std::string sql = “select * from DICT”;        //our sql statement.
istat->Prepare(sql);  //write the sql statement into the class.
istat->Execute();      //EXECUTE !!!
std::string result;      //we define a string here which used to get the result that returns.
while(istat->Fetch())  //Fetch method is the core method which is used to fetch data from database
istat->Get(“DICT_NAME”,result);  //output to result. Be aware that I here only output the COLUMN “DICT_NAME”

Now, all the result are written in to ‘result’ variable, you can print it out as you wish. What I’m gonna do is to write them into a QListView control. So firstly I defined a QStringList outside the loop which used to store data:

QStringList list;

then I add:

QString qresult = QString::fromStdString(result);   //convert std::string to QString
list.append(qresult); //append the result into a QStringList

in the while() loop, of course behind the istat statement, and show them into the comtrol with:

QStringListModel* qmodel = new QStringListModel();
qmodel->setStringList(list); //bind the QStringList to the model
ui->listView->setModel(qmodel); //bind the QStringListModel to QListView.
//qmodel is a QListView which we created using Qt Design.

Now, we can really say everything is done! Phew:). Here is the snapshot of result.

Set up and Connect to the Firebird Database.

22 Aug

[NB]: please follow up the blog at : https://rongsheng007.wordpress.com if you are reading the article in facebook or other places. Thx.

Firebird database is a database based on the Borland Interbase database. Firebird provides powerful features both on it’s server edition and embedded edition. I personally use this database in desktop application development. This software becomes my first choice since it is free and softwares can access database file without building up the server.(embedded version).

BTW: Firebird database seems to support a variety of operating systems.

Here’s how we do it in Linux/UNIX.

1. choose the edition and download the package of firebird database from sourceforge (currently 2.5 RC3)


2. Unpack the file to a folder (say ~/Document/)

3. Run scripts
for Ubuntu and it’s derived system: $ sudo sh ./install.sh
for other linux/unix, first switch to root user using
# su
then #sh ./install.sh

4. Configuration
go to the folder /opt/firebird/ , run
for Ubuntu $sudo passwd firebird
for other linux/unix: #su passwd firebird
then set the new UNIX password.

5. Test
Now you should be in the folder: /opt/firebird , if you are not in this folder, please switch to this folder.
run the following command as root:
you should see:

Use CONNECT or CREATE DATABASE to specify a database

now try the sql command:
connect ./examples/empbuild/employee.fdb user SYSDBA password ;

note: replace to the password you just set and do not ignore the ‘;’.

now you may see:
Database: ./examples/empbuild/employee.fdb, User: SYSDBA

try another command: show table; (don’t omit the ‘;’)

you may see:
COUNTRY                                      CUSTOMER
DEPARTMENT                           EMPLOYEE
PROJECT                                       PROJ_DEPT_BUDGET

till now, you have successfully configured the firebird database, use “quit;” to exit the command prompt.

Running the Server:

If you want to start the sever rather than using files to open it, you need to start the fbguard session.

open a terminal and direct to folder :  “/opt/firebird/bin/”, then run the following command as root user.

./fbguard             or                ./fbguard -d   (if you want to run it in background)

now the system is started, you can run a GUI tool to examine, try “FlameRobin”. here is a screenshot of the configured firebird database.