Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate .h and .cpp from .ui file

Suppose I have the file about.ui. How can I make the "about.h" and the "about.cpp" from my .ui file? I have to create a .moc file too? How can I compile this after the creaton to see if all ocurred correctly?

like image 801
LucasCaixeta Avatar asked Dec 22 '09 18:12

LucasCaixeta


People also ask

How do you make a .ui file?

To create a . ui file go to File -> New File or Project... In the window that appears select Qt under Files and Classes on the left, then select Qt Designer Form on the right. You'll notice the icon has "ui" on it, showing the type of file you're creating.

What is .ui file in Qt?

ui file is used to create a ui_calculatorform. h file that can be used by any file listed in the SOURCES declaration. Note: You can use Qt Creator to create the Calculator Form project. It automatically generates the main.

What is setupUi in Qt?

setupUi() creates the actual instances of widgets for you. A form that you create in QtDesigner is stored just as XML file.


3 Answers

You don't.
The about.ui generates a ui_about.h which you include in your own about.h

You then create you own class deriving from this class

class about :   public QDialog, public Ui::about
{
    Q_OBJECT;
....
}
like image 176
Martin Beckett Avatar answered Nov 07 '22 21:11

Martin Beckett


Short answer:

In QtCreator there are two ways of create a form from windows assistant: - Qt Designer Form Class - QtDesigner Form

you must create a new "Qt Designer Form Class" instead of "Qt Designer Form", because you choose "Qt Designer Form" qt creator doesn't create the .h and .cpp from .ui file:

Long Answer:

When you create "QTCreator Form" only create .ui file this is useful if you already have an existing class for the UI business logic and you want rebuilt user interface but keep business logic, you can call buttom or components with same name and interchange ui.

like image 23
stbnrivas Avatar answered Nov 07 '22 20:11

stbnrivas


If automatic generation does not work (like in my case) you can use uic to generate the header file manually. uic file.ui > file.h

like image 28
sakisk Avatar answered Nov 07 '22 20:11

sakisk