PDA

View Full Version : qt4.1.1 designer



raphaelf
24th February 2006, 19:24
OS: WINXP
Compiler: MINGW 4.1.1
QT: QT 4.1.1

Hello everybody,
Its really time to make a important step in my live...jump from qt3 to 4 ;)

I have read some docs and tried tutorials..
I have a question about using designer in the right steps:

1. I have created a widget, connection in the designer and save it "test1.ui"
2. I have created by hand a "test1.pro":


TEMPLATE = app
FORMS = test1.ui
SOURCES = main.cpp


3. I have created a main.cpp:


#include "ui_test1.h"
#include <QApplication>


int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QDialog *window = new QDialog;
Ui::Dialog ui;
ui.setupUi(window);

window->show();
return app.exec();
}



4. compile and get exe file

My Question: how to get a cpp file to implement my functions?And are my steps correct?Have i to create by hand the cpp? Its right that if i include "ui_test.h" in main.cpp the file will created?Have i to create the main.cpp by hand?

I want to use the designer to design my app ;)

axeljaeger
24th February 2006, 21:02
Looks like you followed this document:

http://doc.trolltech.com/4.1/designer-using-a-component.html

Scroll down to http://doc.trolltech.com/4.1/designer-using-a-component.html#the-single-inheritance-approach

or further to see examples where you can hook in your code.

GreyGeek
24th February 2006, 23:43
OS: WINXP
Compiler: MINGW 4.1.1
QT: QT 4.1.1

Hello everybody,
Its really time to make a important step in my live...jump from qt3 to 4 ;)
...snip...
My Question: how to get a cpp file to implement my functions?And are my steps correct?Have i to create by hand the cpp? Its right that if i include "ui_test.h" in main.cpp the file will created?Have i to create the main.cpp by hand?

I want to use the designer to design my app ;)

I jumped from QT3 to QT4 too, and below is a link to an HTML file that explains how I made my first app under Qt4. Also, I use the designer for the gui's.

http://www.qtcentre.org/forum/attachment.php?attachmentid=75&d=1138742423

sunil.thaha
25th February 2006, 06:09
But that link is not accessible to anyone but you

wysota
25th February 2006, 08:44
But that link is not accessible to anyone but you


Is it? I can read it fine.

raphaelf
25th February 2006, 19:41
hi everybody, thx for all replies..

I hope i am in the right way

Please let me now if i am in the right way or not, AND WHY I CANT SEE A Messagebox after clicking my okButton ;(

my steps:
1. Design my MainWindow
2. i have created a main.cpp:


#include "ui_mainwindow.h"
#include <QApplication>


int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QDialog *window = new QDialog;
Ui::MainWindow ui;
ui.setupUi(window);

window->show();
return app.exec();
}

3. I have created a test.h:


#include "ui_mainwindow.h"



class MainWindow : public QDialog
{
Q_OBJECT

public:
MainWindow(QWidget *parent = 0);

public slots:
void myfirstfunction();


private:
Ui::MainWindow ui;



};

4. I have created a test.cpp:


#include "test.h"

#include <QMessageBox>

MainWindow::MainWindow(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);



connect(ui.okButton, SIGNAL(clicked()), this, SLOT(myfirstfunction()));
connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
}

void MainWindow::myfirstfunction()
{
QMessageBox::information(this, "Application name",
"Unable to find the user preferences file.\n"
"The factory default will be used instead.");

}


5. qmake -project

.pro file:


################################################## ####################
# Automatically generated by qmake (2.00a) Sa 25. Feb 22:31:12 2006
################################################## ####################

TEMPLATE = app
TARGET +=
DEPENDPATH += .
INCLUDEPATH += .

# Input
HEADERS += test.h
FORMS += mainwindow.ui
SOURCES += main.cpp test.cpp



6. qmake
7. make I get a exe file without error

By clicking my okButton i cant see my Messagebox by calling myfirstfunction().

wysota
26th February 2006, 10:20
Looks like you have two Ui::MainWindow objects -- one in main (which is used to show widgets) and the other as a private member of MainWindow (which is connected to a slot), meaning, that you have connected the wrong button to the slot. Remove the object from main().

raphaelf
26th February 2006, 10:47
hi wysota, like that it works:


#include "test.h"
#include <QApplication>


int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow m;
m.show();
return app.exec();
}


Wysota, i am using the correct way?
If i would like to not Subclass "ui_mainwindow.h" and use itself, have i to define my functions there and create a new mainwindow.cpp and implement it there?Will "ui_mainwindow.h" not overwritten?

For example if i have 10 Dialogs...Have i everytime to subclass every ui_XXX.h ??

wysota
26th February 2006, 14:57
You should. In theory you probably could try passing a pointer or a reference to your UI structure, but I don't recommend that. Basicly you should either subclass every ui you create or implement a dynamic dialog, which will change according to your needs (for example including dynamic form (UI) loading). If you don't want to subclass every dialog manualy, you can create a script which will do it for you, you'll just need to fill in the details.

raphaelf
26th February 2006, 15:30
hi..
ok so i should subclass it every dialog, mainwindow...
So my example was correct?

wysota
26th February 2006, 16:56
The one in your previous post? Yes.