PDA

View Full Version : How to convert ui file to cpp file in QtCreator?



chipper
13th November 2010, 07:44
Hi, I am new to Qt4 and I am following the official book C++ GUI Programming with Qt4. It said that we can design UI form of the application first and then generate the c++ code for that ui file. In the book, they demonstrated it in Qt Designer and used qmake to generated a makefile that can invoke uic to to this. However, in the QtSDK I downloaded, it only has QtCreator and the the flow seems different. I don't know how to do in the latest SDK. Can someone give me a hand with that?

Thanks.

tbscope
13th November 2010, 07:52
If you only want to use Qt Creator:

Create a new project of your choice. If you start with a Qt Gui application, a .ui file will already be created for you and the .pro file be created to use uic.
You can then add more widgets or dialogs to your project.

http://doc.qt.nokia.com/qtcreator-2.0.1/index.html

chipper
13th November 2010, 08:11
If you only want to use Qt Creator:

Create a new project of your choice. If you start with a Qt Gui application, a .ui file will already be created for you and the .pro file be created to use uic.
You can then add more widgets or dialogs to your project.

http://doc.qt.nokia.com/qtcreator-2.0.1/index.html

I did that. But after that, I still don't know how to invoke uic... I didn't find the uic in the QtCreator and I looked at the bin directory, there was no binary file called "uic".

tbscope
13th November 2010, 08:14
It's automatic

chipper
13th November 2010, 08:21
I did that. But after that, I still don't know how to invoke uic... I didn't find the uic in the QtCreator and I looked at the bin directory, there was no binary file called "uic".

Sorry, I didn't quite get it. Do you mean that by "run qmake" or "build all", uic will be invoked automatically? When I did that, I didn't see the cpp or h file changed according to the ui file...

poporacer
13th November 2010, 17:12
By default the ui file is hidden as it is a generated file and you shouldn't make changes to that file. The reason for this is each time you build/compile the ui file is regenerated to reflect any changes you might have made, so any changes that you made to the file will be lost. If you really want to see the file then in the creator file menu (right under the word Projects) is a directory tree with your files. Above this is and next to the Project frame is a frame with what looks like a funnel. On the arrow next to the right of the funnel thing (filter tree), click on this and uncheck show generated files. The book is a bit difficult to follow, it starts out with code generated forms and widgets and later on briefly describes QT Designer. I think it does this because the Designer part of creator is pretty straight forward and some people like hand coding their forms so it starts there. (one thing to remember, QT Creator is a program that contains several programs so when someone(or the book) is talking about Designer, that is the Designer part of Creator.) Read the book and things might make a little more sense as you get further in.

Sorry, I didn't quite get it. Do you mean that by "run qmake" or "build all", uic will be invoked automatically? When I did that, I didn't see the cpp or h file changed according to the ui file...

The header or cpp file will not be generated, there will be a file that is generated called ui_yourProjectName. This contains the file to generate the "form" that you created in Designer. QT will integrate this into your program automatically. Your .h and .cpp file will not change.
I hope this helps!
Good luck!

ChrisW67
14th November 2010, 01:21
If the ui file is listed in the qmake PRO file FORMS variable then the uic will be run on it and the resulting file compiled. This is not unique to Qt Creator.

Avery
15th November 2010, 13:10
there is a nice tutorial when you start qtcreator. It explains exactly what you want to do.

You'll find it on the welcome screen > TAB Getting Started > Creating a Qt C++ application

Have Fun!

lgmariano
16th November 2010, 13:49
I'm not quite sure that this is what you want, but if you have a "my_file.ui" and want to generate the source code from it, you can do the following:

uic -o my_file.h my_file.ui

chipper
17th November 2010, 07:18
Thank you all!