Presentation is loading. Please wait.

Presentation is loading. Please wait.

A multi-platform GUI-building program

Similar presentations


Presentation on theme: "A multi-platform GUI-building program"— Presentation transcript:

1 A multi-platform GUI-building program
Using Qt4 A multi-platform GUI-building program

2 Basic steps Create a directory (myqt) to contain everything. All work is done IN this directory Start Qt Designer to construct your primary GUI panel Creates myqt.ui which will LATER be converted into ui_myqt.h Create main.cpp it must have this name or you have to modify the .pro file Run: qmake-qt4 -project {-o xxx} Creates the initial xxx.pro file The default (where xxx is myqt) will be the name of the containing directory Run: qmake-qt4 xxx.Pro Uses the xxx.pro file to create a makefile Use a text editor to create xxx.h Use a text editor to create xxx.cpp Rewrite main.cpp to use the above files Re-run: qmake-qt4 –project {-o xxx} this will add the xxx.cpp file Re-run: qmake-qt4 xxx.Pro Run make Add more C++ code to continue the implementation. Reference:

3 This is the original “main.cpp” (created by hand)
#include <QApplication> #include <QDialog> #include "ui_xxx.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); Ui::xxx ui; QDialog *dialog = new QDialog; ui.setupUi(dialog); dialog->show(); return app.exec(); }

4 xxx.h created by hand // NOTE there is no “ui_” prefix here
#ifndef xxx_H #define xxx_H  #include <QDialog> #include "ui_xxx.h" class xxx : public QDialog, public Ui::xxx { Q_OBJECT public: xxx(QWidget *parent = 0); private slots: void on_lineEdit_textChanged(); }; #endif

5 NEW main.cpp (after initial build)
#include <QApplication> #include "xxx.h" // NOTE no “ui_” prefix on the name here!! int main(int argc, char *argv[]) { QApplication app(argc, argv); xxx *dialog = new xxx; dialog->show(); return app.exec(); }

6 Files after 1st make. Folder name = qt4GUI
hand-created (textfiles or qt Designer): djdialog1.ui djmain.cpp djdialog1.cpp djdialog1.h qt-created qt4-GUI.pro ui_djdialog1.h moc_djdialog1.cpp Makefile results of make djdialog1.0 moc_djdialog1.o qt4-GUI

7 #include <QtGui> #include "djdialog1
#include <QtGui> #include "djdialog1.h" // note: no "ui_" prefix here #include <sstream> #include <string> int int1, int2, answer; djdialog1::djdialog1(QWidget *parent) : QDialog(parent) { setupUi(this); // initialize my form connect(int1box, SIGNAL(textChanged(const QString &)), this, SLOT(on_int1box_textChanged())); connect(int2box, SIGNAL(textChanged(const QString &)), this, SLOT(on_int2box_textChanged())); connect(GoButton, SIGNAL(clicked()), this, SLOT(accept())); }

8 void djdialog1::on_GoButton_clicked()
{ QString qreply; qreply=QString::number(answer); answerbox->append(qreply); } void djdialog1::on_int1box_textChanged(const QString &arg) {bool ok; int1 = arg.toInt(&ok,10); void djdialog1::on_int2box_textChanged(const QString &arg) int2 = arg.toInt(&ok,10);}


Download ppt "A multi-platform GUI-building program"

Similar presentations


Ads by Google