I’m using Qt with Visual Studio 2010 but I have a doubt.
Whenever I use the Qt Designer to create a GUI, when compiling in Visual I have no access to the Objects auto created by the designer, like the buttons, listboxes etc…
What should I do in order to use them ?
My point is, I can’t create events, slots, signals, etc, cause it seems this objects do not exist in my main.cpp and my mainclass.cpp.
Thanks guys !
I’m using VS 2010 with QT 4.8.0.
#include <QListWidget.h>
#include <stdio.h>
#include <string.h>
#include "ui_ratagbc.h"
class dasm: QObject
{
Q_OBJECT
public:
dasm(void);
~dasm(void);
int DAsm(FILE *,int);
private:
Ui::RataGBCClass *ui;
};
To access the GUI in your code, include the result from running the
uictool. Create a class, and have as a member variable an instance of the class thatuicgenerated, it is in the Ui namespace.You get access through this ‘ui’ object:
ui.label->setText("New label text set in source file");In your constructor, call
ui.setupUi(this)Note the Q_OBJECT macro – if you’re defining signals and slots or stuff like that, you need the Q_OBJECT there to flag the class for the
moctool to recognize it.Edit to answer followup question in comments:
It sounds like what you want to do is use the signal/slot system. In your class definition, include the following:
Then someplace else, commonly in the constructor or an initialization function, inclue this line:
The
moctool handles the bulk of the setup. Your custom slot will then be triggered when the button is clicked.