Results 1 to 10 of 10

Thread: How to convert ui file to cpp file in QtCreator?

  1. #1
    Join Date
    Nov 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to convert ui file to cpp file in QtCreator?

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: How to convert ui file to cpp file in QtCreator?

    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

  3. #3
    Join Date
    Nov 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to convert ui file to cpp file in QtCreator?

    Quote Originally Posted by tbscope View Post
    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".

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: How to convert ui file to cpp file in QtCreator?

    It's automatic

  5. #5
    Join Date
    Nov 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to convert ui file to cpp file in QtCreator?

    Quote Originally Posted by chipper View Post
    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...

  6. #6
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to convert ui file to cpp file in QtCreator?

    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!

  7. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,546
    Thanks
    13
    Thanked 1,578 Times in 1,507 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to convert ui file to cpp file in QtCreator?

    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.

  8. #8
    Join Date
    Nov 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to convert ui file to cpp file in QtCreator?

    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!

  9. #9
    Join Date
    Nov 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to convert ui file to cpp file in QtCreator?

    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

  10. #10
    Join Date
    Nov 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to convert ui file to cpp file in QtCreator?

    Thank you all!

Similar Threads

  1. QtCreator add a pri file without compiling it
    By bunjee in forum Qt Tools
    Replies: 1
    Last Post: 3rd May 2009, 13:35
  2. Convert doc into txt file using Qt
    By live_07 in forum Qt Programming
    Replies: 1
    Last Post: 23rd January 2009, 14:27
  3. Read binary file and convert to QString
    By jaca in forum Qt Programming
    Replies: 12
    Last Post: 13th June 2008, 23:05
  4. Replies: 3
    Last Post: 25th May 2007, 07:49
  5. How to convert QTextDocument to PNG file?
    By Gonzalez in forum Qt Programming
    Replies: 1
    Last Post: 2nd February 2006, 14:46

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.