PDA

View Full Version : source and implementation



shrikarcse
28th March 2006, 09:47
hey i have created a form ok then i generated the source using uic. In the form itself i have implemented slot and signals. now i have three file form1.ui,form1.h and form1.cpp.
now i want to have the instance of it in my main.cpp . so that i can produce an executable.
what shud i need to do.
plz help me
if possible give me a snippet of code

Kapil
28th March 2006, 09:50
hey i have created a form ok then i generated the source using uic. In the form itself i have implemented slot and signals. now i have three file form1.ui,form1.h and form1.cpp.
now i want to have the instance of it in my main.cpp . so that i can produce an executable.
what shud i need to do.
plz help me
if possible give me a snippet of code

what version of QT you are using... and platform used...

Kapil
28th March 2006, 10:03
you create an object of ur form class in the main and then call the UI function of it, which sould enable the display of the ui..

Then make it form_obj->show();

main.cpp


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

QMainWindow *form = new QMainWindow;
Ui::MainWindow ui;
ui.setupUi(form);

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


then execute ur project...

zlatko
28th March 2006, 10:56
you create an object of ur form class in the main and then call the UI function of it, which sould enable the display of the ui..

Then make it form_obj->show();

main.cpp


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

QMainWindow *form = new QMainWindow;
Ui::MainWindow ui;
ui.setupUi(form);

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


then execute ur project...

Its validate only for Qt4...

You dont must use uic. Use qmake for bulding your project.

1) subclass you form class



/////// formnew.h

#include "from1.h"
class FormNew::Form1()
{
}


2) write main app function



#include "formnew.h"
int main( int argc, char ** argv )
{
QApplication a( argc, argv );

QFormNew frm;
a.setMainWidget(&frm);
frm.show();

a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
return a.exec();
}


3) read about qmake ;)

shrikarcse
28th March 2006, 16:24
hey is there a way to generate the source from the *.ui form using qmake.
as far as i know qmake is used to generate the makefile when the .cpp and .h files are present.

but i want really is the generation of those .cpp and .h files from qmake
help needed:confused:

zlatko
28th March 2006, 16:50
Read this tutorial (Look here)

Kapil
29th March 2006, 05:02
This information is in support with QT4

There is no need to create the .h files explicitly by running the "uic" command on *.ui files..
What you have to do is just include proper file name at the top of your main.cpp.. In QT4 the .h files are auto generated from your ui files...

for eg. if your ui file is Form.ui then you will have to include-> #include "ui_form.h"..

after you are done with "qmake", when you run "make" this file is generated...

try it out and see it urself...