[Qt-interest] Multi-thread GUI app. using signal/slot
Gino
ginovh2002 at yahoo.com
Sat Apr 24 21:20:10 CEST 2010
Hi,
I want to make a GUI for displaying real-time data from a simulation.
As the simulation is compute intensive it is natural to use 2 threads: 1 for
the GUI and 1 for the simulation.
So my main would look like:
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
systemc_thread sc_simulation;
sc_simulation.start();
// plot widget
Plotter plotter;
plotter.show();
app.exec();
sc_simulation.wait();
}
It is important that from the moment the simulation has data ( let's say one
QPointF ) that the plotter get's updated.
I define systemc_thread as
class systemc_thread : public QThread
Some background on the simulation: it is a SystemC / SystemC-AMS simulation
( if you want more info, please look here, http://www.systemc.org/home)
Without going to much into detail: I need to use another API to structure
the simulation.
I need to call a sc_main() method ( which I put in QThread::run() ). Inside
sc_main() I can instantiate my simulation objects. Such a simulation object
inherits from QObject ( so I can use signal/slots ) and from sc_module.
Like (only show code snippets):
void systemc_thread::run()
{
sc_main();
}
int sc_main()
{
// sc_modules
sca_tdf::sca_signal<double> sig1;
sin_src src("src", 1.0, 1.0e2);
//...
}
class sin_src : public QObject, public sca_tdf::sca_module
{
// ...
public slots:
void setAmplitude(double value) { ampl = value; };
void setFrequency(double value) { freq = value; };
signals:
void send_sampled_data_to_plotter(QPointF newDataPoint);
}
But my problem now is:
how can I connect the signals and slots from sin_src in my main thread to
the signals and slots from plotter?
I need to write something like this in main():
connect(<pointer to sin_src>, send_sampled_data_to_plotter(), &plotter,
receive_data())
But I can't get pointer to sin_src in main().
In the main thread I only have pointer to thread class, which calls method
which instantiates the objects I need pointers to. I can't instantiate them
outside of sc_main.
My questions:
- is there an easier way of sending data and synchronizing these 2 objects ?
Not using signal/slot?
- do I miss something basic/trivial in the setup above?
Any advice is welcome.
Thanks,
best regards,
Gino
More information about the Qt-interest-old
mailing list