Converting qt3 forms to qt4 format

Started by Corfiot, August 24, 2009, 10:24:05 PM

Previous topic - Next topic

0 Members and 19 Guests are viewing this topic.

Corfiot

On win32 the QT 4.4.3 designer is giving me the option to save forms in the new format.

If I convert some forms to qt4, would this be a good thing(tm)?

Liviu Lalescu

No, if it were that easy I would do that myself :-)

You need to convert also the code and add custom slots and connections.

Corfiot

Well yes, that would be the point of the exercise.

Corfiot

I converted a form to check if I can find a minimal process. How about this 6-line patch for example? Seems easy and is working for me (super minimal testing done: just added a couple of activities).

Obviously, there could be other forms that don't quite match this process, which is why I'm asking for your input. If not, I could actually come up with a script for people to use if they want to work on an old 3.3 form to convert it as necessary. Or I could convert everything myself. Would you be OK with a qt Designer 4 requirement?

(This is on win32)

run:
uic3 -convert addactivityform_template.ui > addactivityform4.ui

Apply patch (rev261 is 5.10.3):
Index: addactivityform.cpp
===================================================================
--- addactivityform.cpp      (revision 261)
+++ addactivityform.cpp      (working copy)
@@ -58,6 +58,7 @@

AddActivityForm::AddActivityForm()
{
+      setupUi(this);
      /*setWindowFlags(windowFlags() | Qt::WindowMinMaxButtonsHint);
      QDesktopWidget* desktop=QApplication::desktop();
      int xx=desktop->width()/2 - frameGeometry().width()/2;
Index: addactivityform.h
===================================================================
--- addactivityform.h      (revision 261)
+++ addactivityform.h      (working copy)
@@ -18,7 +18,7 @@
#ifndef ADDACTIVITYFORM_H
#define ADDACTIVITYFORM_H

-#include "addactivityform_template.h"
+#include "ui_addactivityform4.h"

#include "timetable_defs.h"
#include "timetable.h"
@@ -36,7 +36,7 @@
#include <q3textedit.h>


-class AddActivityForm : public AddActivityForm_template  {
+class AddActivityForm : public QDialog, private Ui::AddActivityForm_template  {
      Q_OBJECT

public:
Index: interface.pro
===================================================================
--- interface.pro      (revision 261)
+++ interface.pro      (working copy)
@@ -734,6 +734,7 @@
                        ../../translations/fet_fa.ts \
                        ../../translations/fet_untranslated.ts
FORMS+=  fetmainform_template.ui \
+      addactivityform4.ui \
      helpaboutform_template.ui \
      teachersstatisticsform_template.ui \
      subjectsstatisticsform_template.ui \
@@ -751,7 +752,6 @@
             helptipsform_template.ui \
             helpinstructionsform_template.ui \
         activitiesform_template.ui \
-         addactivityform_template.ui \
         modifyactivityform_template.ui \
\
         subactivitiesform_template.ui \


Delete
addactivityform_template.ui

Liviu Lalescu

Indeed, Corfiot, you are right, converting is easier than I thought. I see that the conversion keeps the custom connections - I thought this was not possible. But it would be also elegant to get rid of Qt 3 classes (like Q3GroupBox). Also, I fear the custom connections might be lost in some cases, I am not sure. I'll read about that in Qt documentation.

Liviu Lalescu

Link:

http://doc.trolltech.com/4.4/porting4-designer.html

Quote:

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:

This is what I fear. Maybe your conversion is not perfect and connections may be lost.

Corfiot

yes, if you just save it as v4 from the designer. But read what the docs say right after:

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.

I'm using uic3. but I can edit the form in qtdesigner4, too. Yep, it's in v4 format.

Concerning the slots, I used the multiple inheritance method so the events work ok because all the event code is untouched and I reused your cpp of the implementation of the slots.

I tried the direct method first but that displayed a blank form, which is what happens when signals dont work. So now the dialog is working ok as far as I can tell.

--G

Liviu Lalescu

Quoteyes, if you just save it as v4 from the designer. But read what the docs say right after:

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.

I'm using uic3. but I can edit the form in qtdesigner4, too. Yep, it's in v4 format.

I am using this trick for current FET. That is why you need Qt 3 Designer to open them.

Quote
Concerning the slots, I used the multiple inheritance method so the events work ok because all the event code is untouched and I reused your cpp of the implementation of the slots.

I tried the direct method first but that displayed a blank form, which is what happens when signals dont work. So now the dialog is working ok as far as I can tell.

--G

The dialog is blank because you didn't call "setupUi(this)".

Corfiot

You don't need qt3 designer to open the one I converted. It's qt4 designer compatible.

Also, the form had its components, just not the data in the lists (the constructor and generally the implementation was not hooked up). But that is irrelevant, it's working for me with the patch I mentioned. As I said, I added activities with my build.


Liviu Lalescu

#9
I meant that using the trick Qt describes keeps the form in Qt 3. If you update it to Qt 4, then they say that you need to rewrite all custom slots and connections. That's the official explanation, although it seems that this step is not necessarily needed. But I am afraid there might be some problems.

Corfiot

No it doesn't. It keeps the Qt3 classes but the form is turned into QT4. I did the "uic3 -convert". I then applied the patch, qmake, make and it all works. I can edit the form in qt designer 4.

In ui_addactivityform4.h, which is automatically created by uic, I see the SLOTS being connected:

 QObject::connect(forceAdjacentCheckBox, SIGNAL(toggled(bool)), AddActivityForm_template, SLOT(activityChanged()));
   QObject::connect(nStudentsSpinBox, SIGNAL(valueChanged(int)), AddActivityForm_template, SLOT(activityChanged()));
   QObject::connect(active8CheckBox, SIGNAL(toggled(bool)), AddActivityForm_template, SLOT(activityChanged()));
   QObject::connect(active7CheckBox, SIGNAL(toggled(bool)), AddActivityForm_template, SLOT(activityChanged()));
   QObject::connect(active6CheckBox, SIGNAL(toggled(bool)), AddActivityForm_template, SLOT(activityChanged()));
   QObject::connect(active5CheckBox, SIGNAL(toggled(bool)), AddActivityForm_template, SLOT(activityChanged()));
   QObject::connect(active4CheckBox, SIGNAL(toggled(bool)), AddActivityForm_template, SLOT(activityChanged()));
   QObject::connect(active3CheckBox, SIGNAL(toggled(bool)), AddActivityForm_template, SLOT(activityChanged()));



I suspect their tool is more up-to-date than the actual instructions.

I worry about problems, too but because it's the GUI, it's easier to fix since problems are usually easy to see. I am thinking of converting some more forms to test more.

Any suggestions as to which to do first?

Liviu Lalescu

#11
Yes, you are right, but still I am afraid. Because some problems might arise and users might find a useless menu.

The correct way would be to take all custom slots and connections and add them in the C++ code (for example in addactivityform.cpp). This is why I consider this very complicated, as there are about 300 files to modify. I'll think about it, anyway. I am not afraid of work, but I am afraid that I might do some hidden bugs and people would have big problems and very few people actually report bugs, most will abandon FET.

I do not have any of order of preference.

Corfiot

Why would you want to do that? The whole point of using the designer is to get away from adding the code manually. Slots and signals in our case are a almost completely a GUI-side issue anyway (buttons and so on), so I don't see any benefit in having signal/slot code separate from the forms themselves. Why not have them automatically generated?

Naturally, if you are using slots and signals between actual internal objects to share data/state, we should keep those away from the forms.

I was thinking to convert all the forms this way so we can get rid of the qt designer 3.3 requirement. Then we can decide if we want to actually replace the qt3 components on the forms on a form by form basis, as needed. I just want to be able to work on forms in win32.

Liviu Lalescu

I want the simplest way. But adding custom connections into a Qt 4 form is officially (described in Qt 4 help) impossible, the correct way is to add custom slots and connections in the code. That is what they say. You found a working solution, but I think it is not a perfect way and editing some forms might loose connections, which is disatruous.

I'll think about converting in the perfect way. I'll try to think about it.

Liviu Lalescu

More details: open a converted file with Qt 4 Designer. See connections. If you click or double click on a custom slot, the Designer writes there "<slot>", so it does not recognize the slot. The correct way is to write in the C++ code, like I wrote previously.

I'll think about converting the correct way, but I am not sure I'll be able to do it soon.