Do QLabels and QTextEdits get updated automatically ?
-
Hi,
I am creating a GUI which I want displaying parameters from a camera (Using QTango). If the camera parameters change, I expect to automatically see the changes on my GUI in the QLabels straight away without interaction.
I have my mainwindow.h , mainwindow.cpp, ui_mainwindow.h and main.cpp files.
I am confused as to where to put the code for this.
Do I create an object of Mainwindow in main.cpp and assign the values to the QLabel of that object there? In that case, doesn't main just get executed once and therefore only put the values once and not updating when they change? Or should the code go elsewhere?
I'm new to Qt and unsure how it works. Thanks
-
Hi,
You should first start with the Qt widget tutorial, you'll have a better grasp on how it works.
@
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MyMainWindow mw;
mw.show();
return app.exec(); <- here is the magic, the event loop starts and you'll have your GUI running until you quit it
}
@Basically you create a subclass of the appropriate widget (QWidget, QDialog, QMainWindow) and modify it to your needs.
-
Is this the only code that goes in the main function?
For example, If I want to assign a variable to a QLabel on my GUI. Do I do it in the main function such as mw.myLabel->setText("") etc. ? Thanks
-
Look into the concept of signals and slots (and note that a function like setText is a slot).