PDA

View Full Version : Visual Studio .NET & QT



fruzzo
2nd December 2007, 13:04
Hi...I use Visual Studio .NET (2003) plus Qt 3.3.5. I've add the Qt toolbar in VS .NET but I've some problems in the interface (integration) between the 2 softwares.
With Qt Designer I create myproject.pro and add some ui to this project, I import the project in VS creating so a VS project. Now if I make some changes in ui with Qt designer, this changes are applicated in VS too but reverse, if I make some changes in the source code with VS the aren't applicated in Qt Designer. Why is there this problem?

And...using Qt Designer, I can't view the source of the mygui.ui...If a press right button of the mouse and Source, it tell my "Want you open a ui.h file?" and clicking yes it open a file ui.h blank? Why? Solutions?

jacek
2nd December 2007, 20:13
if I make some changes in the source code with VS the aren't applicated in Qt Designer. Why is there this problem?
Does this mean that you edit the code generated automatically from .ui files?

fruzzo
3rd December 2007, 19:45
Does this mean that you edit the code generated automatically from .ui files?

Yes I import the project .pro in VS...than I change code adding the body of members functions...
I read about subclassing but I don't understand very well the mechanism :(

jacek
3rd December 2007, 20:07
Yes I import the project .pro in VS...than I change code adding the body of members functions...
Is that the .ui.h file?


I read about subclassing but I don't understand very well the mechanism :(
It's not that hard, every .ui file represents a class, which you can subclass to add whatever functionality you need. The integration module probably can do that for you.

fruzzo
3rd December 2007, 20:26
Is that the .ui.h file?


It's not that hard, every .ui file represents a class, which you can subclass to add whatever functionality you need. The integration module probably can do that for you.

Qt 3.3 don't have integration module for VS.
Now I'm think to pass to VS2005...there is something like QMsNetSetup.msi for adding Qt toolbar at VS2005?

fruzzo
3rd December 2007, 21:14
Is that the .ui.h file?

no I create a gui called myGUI.ui.......than in VS I have myGUI.ui, myGUI.h and myGUI.cpp
and I modify this last two.

jacek
3rd December 2007, 22:00
no I create a gui called myGUI.ui.......than in VS I have myGUI.ui, myGUI.h and myGUI.cpp
and I modify this last two.
I see, that's what I was afraid of. You shouldn't do that. There are even warnings in those files, which say that. It's because these files are automatically generated everytime you change the .ui file, which means that you will loose all your modifications.

That's why you should use the subclassing approach (it will also save you a bit of pain, when you switch to Qt4). First you have to rename yourGUI.ui to yourGUISkel.ui (or youGUIBase.ui or whatever name you like) and also you will have to rename the widget from yourGUI to yourGUISkel (using Qt Designer). This way Qt will generate youGUISkel class instead of yourGUI. It's because you're going to write yourGUI yourself. It should look like this:
// yourGUI.h
#include "yourGUISkel.h"

class yourGUI : public yourGUISkel
{
Q_OBJECT
yourGUI( QWidget * parent );
...
};

// yourGUI.cpp
#include "yourGUI.h"

yourGUI::yourGUI( QWidget * parent )
: yourGUISkel( parent )
{
...
}

Since there is Q_OBJECT macro in yourGUI.h, you need yourGUI.moc file (qmake will make it for you --- you just have to add yourGUI.h to HEADERS variable and yourGUI.cpp to SOURCES in the .pro file and re-run qmake).

Now you can safely edit the youGUISkel.ui file in Qt Designer and add implementation in yourGUI.{h,cpp} files.