Communication between widgets
-
Hi,
Qt's documentation is filed with these kind of examples and demos. You should be able to get them all together and work with the Qt. .
-
Hi,
So you want to send data from mainwidget class to second widget. class
Here is the sample code.class MainwidgetClass : public QObject{
Q_OBJECT;
...
public signals:
void yourSignal();
};...
class SecondWidgetClass: public QObject{
Q_OBJECT;
...
public slots:
void slotFunc();
}MainwidgetClass *youObject = new MainwidgetClass ;
connect(MainwidgetClass , SIGNAL(yourSignal()), SecondWidgetClass, SLOT(someSlot()));so if you want to send the data from the first MainwidgetClass class then you have use emit call emit yourSignal();
And establish the connect between the two classes. U will recieve data in slotFunc() of
SecondWidgetClass Class. -
Hi,
So you want to send data from mainwidget class to second widget. class
Here is the sample code.class MainwidgetClass : public QObject{
Q_OBJECT;
...
public signals:
void yourSignal();
};...
class SecondWidgetClass: public QObject{
Q_OBJECT;
...
public slots:
void slotFunc();
}MainwidgetClass *youObject = new MainwidgetClass ;
connect(MainwidgetClass , SIGNAL(yourSignal()), SecondWidgetClass, SLOT(someSlot()));so if you want to send the data from the first MainwidgetClass class then you have use emit call emit yourSignal();
And establish the connect between the two classes. U will recieve data in slotFunc() of
SecondWidgetClass Class.@Pradeep-Kumar
That's not valid code.
It should be:MainwidgetClass *youObject = new MainwidgetClass ; SecondWidgetClass *secondWidget = new SecondWidgetClass(); connect(youObject , SIGNAL(yourSignal()), secondWidget, SLOT(slotFunc()));You need pointer to class instances, you cannot pass a class to connect.
-
@jsulm
Sorry for that how could i miss that.Mistake corrected.
class MainwidgetClass : public QObject{
Q_OBJECT;
...
public signals:
void yourSignal();
};...
class SecondWidgetClass: public QObject{
Q_OBJECT;
...
public slots:
void slotFunc();
}MainwidgetClass *youObject = new MainwidgetClass ;
SecondWidgetClass *secondWidget = new SecondWidgetClass;connect(youObject , SIGNAL(yourSignal()), secondWidget, SLOT(slotFunc()));
Thanks for correcting me @jsulm