PDA

View Full Version : Visual Studio 10 with Qt Addin--Can I avoid running qmake -tp vc?



davethomaspilot
12th June 2012, 00:47
I keep having problems for which the recommended solution seems to be "rerun qmake".

Example, I just created a new exposure_controls.ui using Qt Designer and the only way I know to get a ui_exposure_controls.h is to:

1) create a header file (call it exposure_controls.h") that defines a new class which:
a) includes "ui_exposure_controls.h"
b) defines a class (call it Exposure) which inherits from the class defined in exposure_controls.ui (and other Qt objects)
c) has a Q_OBJECT macro

2) Create an instance of the Exposure class.

3) Run qmake -project;qmake QtApe1.pro; qmake -tp vc QtApe1.pro

seems overly complicated--I suspect I'm missing something.

Also while this is working for me, whenever I do step 3, a property sheet I have added to the Visual Studio 10 for non-QT libraries gets excluded. So, I have to re-add it each time after doing the qmake stuff.

Seems like there should be a better way?

Also--

I have a MainWindow with a few slots and connects to simple methods. It's working, but now I wonder about "Best Practices". For example, I created a widget with sliders and push buttons. I want it to be displayed when one of the menu items is clicked.

Do I just add that widget as a data member of the MainWindow class? Same for any associated methods? I'm worrying that I'll end up with a huge MainWindow class and that there might be a better way.

Thanks,

Dave Thomas

ChrisW67
12th June 2012, 01:09
qmake will create a ui_*.h file for any *.ui file listed in the PRO file FORMS variable.

The typical usage pattern for that intermediate ui_*.h file is through user-defined class as you describe. See Using a Designer UI File in Your Application for options. The header and source file for that user class should be listed in the pro file HEADERS and SOURCES variable respectively. You only need do this once, and you certainly should not be running "qmake -project", which creates a basic starter PRO file, routinely. Any time you modify the PRO file you need to re-run "qmake" once (not twice) and typically with no arguments other than a path to the PRO file if it is not in the current directory. Modifying the referenced UI, source, or header files does not generally require rerunning qmake unless you add or remove Q_OBJECT macros.

I don't use the VC plugin but I would assume that most of this is done for you. Perhaps someone who does use it could shed light.


For a pop-up dialog style of thing you would put the code for handling the dialog UI, e.g. interaction between widgets within the dialog etc., in the dialog class along with any access methods you need for outside users. The main window then only need to create an instance of the dialog class and exec() or show() it. Code to access the values in the dialog and do something with them has to exist somewhere, and the "correct" location is application dependent.

davethomaspilot
12th June 2012, 01:40
Thanks for the quick reply!

Right now I'm "evolving" from using fairly crude mechanisms in openCV's highgui to use Qt widgets instead. I'm doing one small bit at a time, so I'm really adding a QOBJECT frequently.

So, I only need to run qmake once each time I add a QOBJECT But, when I run qmake -tp vc it detaches my property pages from the Visual Studio 10 project. I was hoping there was something I could do in Visual Studio so I wouldn't have to run qmake, or, do something so I don't have to redo the Visual Studio 10 properties after each qmake.

Thanks for the guidance on how to organize the code.

Dave Thomas