steps to convert qt3 to qt4
how i can convert qt3 format to qt4 format using uic3 in clear steps?开发者_高级运维
Qt 4 comes with the tool uic3 for working with old .ui files. It can be used in two ways:
- To generate headers and source code for a widget to implement any custom signals and slots added using Qt Designer 3.
- To generate a new UI file that can be used with Qt Designer 4.
You can use both these methods in combination to obtain UI, header and source files that you can use as a starting point when porting your user interface to Qt 4.
uic3 myform.ui > myform.h
uic3 -impl myform.h myform.ui > myform.cpp
The resulting files myform.h and myform.cpp implement the form in Qt 4 using a QWidget that will include custom signals, slots and connections specified in the UI file. However, see below for the limitations of this method.
The second method is to use uic3 to convert a Qt Designer 3 .ui file to the Qt Designer 4 format:
uic3 -convert myform3.ui > myform4.ui
The resulting file myform4.ui can be edited in Qt Designer 4. The header file for the form is generated by Qt 4's uic. See the Using a Designer UI File in Your Application chapter of the Qt Designer Manual for information about the preferred ways to use forms created with Qt Designer 4.
Note :There are Limitations of uic3:
Converting Qt 3 UI files to Qt 4 has some limitations. The most noticeable limitation is the fact that since uic no longer generates a QObject, it's not possible to define custom signals or slots for the form. Instead, the programmer must define these signals and slots in the main container and connect them to the widgets in the form after calling setupUi(). For example:
class HelloWorldWidget : public QWidget, public Ui::HelloWorld
{
Q_OBJECT
public:
HelloWorldWidget(QWidget *parent = 0);
public slots:
void mySlot();
};
HelloWorldWidget::HelloWorldWidget(QWidget *parent)
: QWidget(parent)
{
setupUi(this);
QObject::connect(pushButton, SIGNAL(clicked()),
this, SLOT(mySlot()));
}
void HelloWorldWidget::mySlot()
{
...
}
A quick and dirty way to port forms containing custom signals and slots is to generate the code using uic3, rather than uic. Since uic3 does generate a QWidget, it will populate it with custom signals, slots and connections specified in the UI file. However, uic3 can only generate code from Qt 3 UI files, which implies that the UI files never get translated and need to be edited using Qt Designer 3.
Note also that it is possible to create implicit connections between the widgets in a form and the main container. After setupUi() populates the main container with child widgets it scans the main container's list of slots for names with the form on_objectName_signalName().
If the form contains a widget whose object name is objectName, and if that widget has a signal called signalName, then this signal will be connected to the main container's slot. For example:
class HelloWorldWidget : public QWidget, public Ui::HelloWorld
{
Q_OBJECT
public:
HelloWorldWidget(QWidget *parent = 0);
public slots:
void on_pushButton_clicked();
};
HelloWorldWidget::HelloWorldWidget(QWidget *parent)
: QWidget(parent)
{
setupUi(this);
}
void HelloWorldWidget::on_pushButton_clicked()
{
...
}
Because of the naming convention, setupUi() automatically connects pushButton's clicked() signal to HelloWorldWidget's on_pushButton_clicked() slot.
I got this solution from http://qt.developpez.com/doc/4.7/porting4-designer/
精彩评论