One signal to two window
-
then where you have the generation code you simply take that variable from there - from the constructor and connect it. just after it was constructed or generated
-
Here is an example based on the sources you posted before.
See my comments below started with // <<-
MainWindow.h
@
class MainWindow : public QMainWindow
{
...
rtk_thread* worker; // << Declare worker in MainWindow
RoverSatView* roverSatView;
};
@ -
MainWindow.cpp
@
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);QThread* rtkthread = new QThread;
worker = new rtk_thread; // << Initialize it in ctor
...
worker->moveToThread(rtkthread);
connect(rtkthread, SIGNAL(started()), worker, SLOT(run()));
connect(worker, SIGNAL(finished()), rtkthread, SLOT(quit()));
connect(worker, SIGNAL(finished()), worker, SLOT(deleteLater()));
connect(rtkthread, SIGNAL(finished()), rtkthread, SLOT(deleteLater()));
rtkthread->start();
}
void MainWindow::createRoverSatView()
{
roverSatView = new RoverSatView(worker, this); // << pass it to RoverSatView
...
}
@-
RoverSatView.h
@
class RoverSatView : public QWidget
{
Q_OBJECT
public:
RoverSatView(rtk_thread* rtkWorker, QWidget *parent = 0);
// << ctor accepts the worker from MainWindowprotected:
void paintEvent(QPaintEvent *event);private slots:
void slot_rtk_rover_sat_azel_in(const SatList &sats);private:
SatList satellites;
rtk_thread* worker; // << it will keep worker from MainWindow
};
@ -
RoverSatView.cpp
@
RoverSatView::RoverSatView(rtk_thread* rtkWorker, QWidget* parent)
: QWidget(parent)
, worker(rtkWorker) // << initialize using worker from MainWindow
{
// Initialize the Qt magic
connect(worker, SIGNAL(rtk_rover_sat_azel(SatList)),
this, SLOT(slot_rtk_rover_sat_azel_in(SatList)));
}
@
-
-
You can use "QTabWidget::addTab()":http://qt-project.org/doc/qt-5/qtabwidget.html#addTab to put your widget into generated QTabWidget
-
Hello,
This is working:
@connect(worker,SIGNAL(active_window(double)),this,SLOT(slot_active_window(double)));@This is not working:
@connect(this,SIGNAL(active_window(double)),worker,SLOT(slot_active_window(double)));@Both in same place. I want to connect the thread (worker) and a window (this) in both direction.
Why the second not working? Or I have to put the "connect..." to the SLOT side? -
No error and no messages, just the value is not send or receive from MainWindow to worker. From worker to MainWidow working, value send and receive.
@
class rtk_thread:public QObject
{
Q_OBJECT
public:
rtk_thread();
~rtk_thread();signals:
void active_window(double);private slots:
void slot_active_window(double);};@
@class MainWindow : public QMainWindow
{
Q_OBJECTpublic:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();Ui::MainWindow *ui; QDialog *win_GPS; rtk_thread* worker;
public slots:
private slots:
void slot_active_window(double);signals:
void active_window(double);private:
};@
MaiWidow.cpp
@MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);QThread* rtkthread=new QThread; worker=new rtk_thread; win_GPS = new GPSwindow(worker);
worker->moveToThread(rtkthread);
connect(rtkthread, SIGNAL(started()), worker, SLOT(run()));
connect(worker, SIGNAL(finished()), rtkthread, SLOT(quit()));
connect(worker, SIGNAL(finished()), worker, SLOT(deleteLater()));
connect(rtkthread, SIGNAL(finished()), rtkthread, SLOT(deleteLater()));
rtkthread->start();
connect(this,SIGNAL(active_window(double)),worker,SLOT(slot_active_window(double)));
connect(worker,SIGNAL(active_window(double)),this,SLOT(slot_active_window(double)));
}@