I would like to know which of the following is the correct way to do things with a signal / slot in Qt.
I need a way to have multiple instances of the dialog, i.e. Aand B. And I need to say Ato print “A” and Bto print “B” from another thread. Therefore, I believe that I need something like:
OPTION 1) A->print("A") andB->print("B")
or better to do:
OPTION 2) emit print("A") and emit print("B")and use a method that I do not know, so only Acatch "A" and only Bcatch "B" ,.
I have option 1 that works as follows:
class myClass : public QMainWindow
{
Q_OBJECT
public:
myClass (QWidget *parent = 0, Qt::WFlags flags = 0);
~myClass ();
void doPrint(char* text)
{
emit mySignal(text);
}
private:
Ui::myClass ui;
public slots:
void newLog(char* msg);
signals:
void mySignal(char* msg);
};
myClass::myClass(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags)
{
ui.setupUi(this);
connect(this, SIGNAL(mySignal(char*)), this, SLOT(newLog(char*)));
}
void myClass::newLog(char* msg)
{
ui.textEdit->append(msg);
}
and then all I need to do is:
myClass* instanceA = new myClass();
myClass* instanceB = new myClass();
instanceA->doPrint("A");
instanceB->doPrint("B");
is that right?
Thanks!
xcimo