PDA

View Full Version : How do I make an executable file from a .ui designer file



ZarehG
3rd February 2010, 00:33
Hi,

I'm new to Qt. I've successfully installed version 4.6.1 on my Linux system and compiled all the libraries. I've also gone into Designer and have created a sample .ui file.

Now I'm lost and confused on how exactly to create an executable file. I've gone through the documentation using Assistant many times and am not getting anywhere. I'm sure uic, qmake and mabe moc have something to do with successfully creating an executable. But can't figure out exactly what I'm suppose to do. Is there a set of explicit instructions on exactly what to do once you have a .ui file to create an executable? I can't find it anywhere. There is talk of creating project files and options here and there, but no step by step instructions on exactly what to do after you have a .ui file. How can I create a .cpp file?

any help would be greatly appreciated.

thank you in advance,
Zareh

qtlinuxnewbie
3rd February 2010, 04:06
After u create a .ui file
Build it either using the tools in Designer or ShortCut key:Ctrl + Shift + B to build and to run Ctrl + R
or u can also generate .cpp files through the terminal but it is a big Procedure.
try the earlier way if not i wil post the next details.

Happy building!

ZarehG
4th February 2010, 23:39
After u create a .ui file
Build it either using the tools in Designer or ShortCut key:Ctrl + Shift + B to build and to run Ctrl + R
or u can also generate .cpp files through the terminal but it is a big Procedure.
try the earlier way if not i wil post the next details.

Happy building!

Thank you for your reply. I can find the Ctrl + R option under the Form menu. It works and allows me to see a running version of my GUI. But I can't find the Ctrl + Shift + B option anywhere in Designer. Where and under what menu is the Ctrl + Shift + B located in Designer.

Thanks again,
Zareh

ZarehG
5th February 2010, 01:28
Yay! I got it to compile and run!
OK, here is how to go from a .ui file (and only a .ui file) to a usable executable in Linux.

Step 1: Let's say your .ui file creates a color picker, in my case I called it ZarehsQtColorPicker.ui
Go to the folder where your .ui file is and type the following command:
> uic -o ZarehsQtColorPicker.h ZarehsQtColorPicker.ui
make sure you're running the correct version of uic. You can specify it's path explicitly if you need to by typing it out, in my case it was something like this: ../../Linux_x86-2010.01/qt-everywhere-opensource-src-4.6.1/bin/uic -oZarehsQtColorPicker.h ZarehsQtColorPicker.ui

At the end of this step you should have a .h file.

Step 2: You have to create a .pro file (Project file). Here is what mine looks like:
CONFIG += qt
HEADERS += ZarehsQtColorPicker.h
SOURCES += main.cpp
Just go into emacs, vi or any text editor you like and type the above 3 lines and save the file. I called my file ZarehsQtColorPicker.pro
You also need to make a main.cpp file. Here is what it should look like:
#include "ZarehsQtColorPicker.h"

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

QWidget *widget = new QWidget;

Ui::ZarehsColorPicker ui;
ui.setupUi(widget);

widget->show();
return app.exec();
}
The only things you need to change are the things colored in green. Just substitute whatever .h file and class name you are using in your example.
OK, now that you have a .pro and a main.cpp file, type this command at the command prompt, making sure you're still in the directory where your .ui and .h file is:
> qmake -o Makefile ZarehsQtColorPicker.pro

Step 3: now you should have a file called "Makefile" in your directory. At the command prompt type make.
> make

that's it. you should now have an executable file in your directory. In my case it's called ZarehsQtColorPicker. I typed
> ./ZarehsQtColorPicker
at the command prompt and it executed and brought up the GUI designed in Designer.

Hope this helps someone out there,
Zareh

duma
30th August 2011, 20:13
Hey thanks, this helped me. But i was wondering, how would i have an icon on my desktop from which i could execute the application.

ChrisW67
30th August 2011, 23:21
how would i have an icon on my desktop from which i could execute the application.
It isn't magic. You (or your installer for deployment) have to create one.

The instructions from qtlinuxnewbie are for Qt Creator, which embeds Designer into a full C++ IDE.