PDA

View Full Version : port qt3 app to desinger 4 ui files



hvengel
26th February 2007, 23:13
I have converted the ui files for my app from designer 3 to designer 4. Now I am looking at the examples trying to figure what I need to do to use the files generated by uic 4. My qt 3 code is structured like this:

mydialogbase.ui contains the MyDialogBase dialog. Then in mydialog.h I subclass the MyDialogBase object like this:



#include "mydialogbase.h"

class MyDialog : public MyDialogBase
{
Q_OBJECT

public:

MyDialog(QWidget *parent = 0);
~MyDialog();

....

};

In mydialog.cpp I have



#include "mydialog.h"

MyDialog::MyDialog(QWidget *parent)
:MyDialog(parent)
{
...
}

MyDialog::~MyDialog()
{
...
}


Then in main.cpp I do this:



#include "mydialog.h"

int main( int argc, char **argv )
{
QApplication a( argc, argv );

MyDialog w;
w.show();
return a.exec();
}

The examples that I have looked at do not appear to be based on qt3 code that is already subclassing the ui object and I am having a hard time figuring out how to make my code work with the new code generated by uic 4. It seems like I should be able to make some minor changes to MyDialog in mydialog.h and possibly mydialog.cpp to make this work. But everything I have tried will not build. Is there someone here that can modify my little example code stubs so that this would correctly interface to the code generated by uic 4? It does not need to be totally perfect just enough so that I know I am on the right track.

jacek
26th February 2007, 23:38
Try:

class MyDialog : public QDialog, public Ui::MyDialogBase
{
Q_OBJECT
public:
...
};
...
MyDialog::MyDialog( QWidget *parent )
: QDialog( parent )
{
setupUi( this );
...
}

Although I prefer the single inheritance approach (http://doc.trolltech.com/4.2/designer-using-a-component.html#the-single-inheritance-approach).

hvengel
27th February 2007, 01:11
Sorry that is basically what I had tried before. I tried it again to make sure. The compiler gives me an error message that points at the end of

class MyDialog : public QDialog, public Ui::MyDialogBase

in mydialog,h and says :

mydialg.h:2: error: expected class-name before '{' token

There could be something else wrong since I can not get the makefile generated by qmake to run uic or moc and I have been doing this by hand (what a pain the the rear). But I was able to get the app to build and run using uic3 before I converted the ui files.

jacek
27th February 2007, 01:45
Try #include "ui_mydialogbase.h" (if your .ui file is called mydialogbase.ui). Make sure you re-run qmake.

hvengel
27th February 2007, 06:14
OK I was having problems with make not running uic and creating the ui header files. After updating all of the header to say things like

#include <ui_mydialogbase.h>

make started creating the ui header files. At that point for the most part this is now working. I do have two of the dialog implementations that are still giving me problems with the setupUI(this) statement. It compiles about 'setupUI' was not declared in this scope. If I comment this line out of both of the dialog implementations it will build and run. Of course none of the signals/slots work and there is lots of functionality that is broken because of that. I know that the setUI(this) line has to be there I just need to figure out why I am getting the compiler errors on two out of seven of these. I can't see why these two are different but it is late and I am tired so I will take a fresh look at it tomorrow.

Thanks for your help I have gotten much farther along and I think I can get the port at least mostly working in the next few days.