Qt GUI example using Qt4 Designer .ui file

Trolltech Qt GUI programming forum.

Qt GUI example using Qt4 Designer .ui file

Postby kamil on January 31st, 2008, 10:14 pm

1) install qt libs and qt designer if need be
2) design a GUI using Qt4 Designer, and save it as .ui file (user interface file), I'll call mine hsle.ui
qt4-designer.png
Qt4 Designer
qt4-designer.png (174.63 KB) Viewed 201 times

3) in the same directory create main.cpp (change the hsle string inside main.cpp if you are using a different name):
Code: Select all
    #include <QApplication>
    #include <QFont>
    #include <QPushButton>
    #include <QWidget>

    #include "hsle.h"

    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);

        QMainWindow w;
        Ui_hsleMainWindow hsle;
        hsle.setupUi(&w);

        w.show();
        return app.exec();
    }

note that the name of the directory that contains your sources is important since it will become the name of your project (see the output of qmake-qt4 -project used next). my directory is also called hsle.
4) run the following to compile your project:
Code: Select all
uic-qt4 hsle.ui -o hsle.h
qmake-qt4 -project
qmake-qt4
make


Here is the compilation output I got:
Code: Select all
uic-qt4 hsle.ui -o hsle.h
qmake-qt4 -project
qmake-qt4
make
/usr/lib/qt4/bin/uic hsle.ui -o ui_hsle.h
g++ -c -pipe -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include/QtGui -I/usr/include -I. -I. -I. -o main.o main.cpp
g++  -o hsle main.o     -lQtGui -lQtCore -lpthread


And here is the GUI produced when I run ./hsle
qt4-gui-app.png
Q4 GUI app
qt4-gui-app.png (12.88 KB) Viewed 199 times
User avatar
kamil
Linux Adept
 
Posts: 118
Joined: January 18th, 2008, 1:22 am
Location: Brisbane, Australia

Return to Qt

Who is online

Users browsing this forum: No registered users and 0 guests

cron

dsplabs homelinux bloglinux forums new! travel photographyawklores new! cryptographyjames' home
©2009 dsplabs.com.au