Reputation: 165
I am writing a Qt application which does some calculations. I would like to separate in my project 2 parts: the part related to GUI and the part which is responsible for calculations. Could you recommend the best way to do so? Examples are appreciated.
My idea was to do it in main.cpp file:
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow mw; // This is responsible for GUI
mw.show();
MainComputation mc; // This is responsible for calculations
return app.exec();
}
I would need also to establish the connections between this two parts.
Upvotes: 2
Views: 379
Reputation: 10931
You need to create your MainComputation
class as shown here (mainly inherit from QObject
, include the Q_OBJECT
macro in your class declaration and label some methods as slots).
Then you will need to hook up signals and slots between your GUI elements signals (mouseClick, buttonPress, etc..., checkout each widgets available signals) and an instance of your MainComputation
objects slots. This is done with the connect
statement. Kinda like this
connect(mw.ui->btn,SIGNAL(clicked(bool)),&mc,SLOT(doSomething()));
There is a simple example with a lot of information available at the qt docs.
Upvotes: 1
Reputation: 12415
You can create a library with the GUI, another library with the calculation algorithms, and exchange data between them using QT signals&slots.
Upvotes: 1