just tried
qRegisterMetaType<MyClass&>("MyClassRef");
qRegisterMetaType<MyClass&>("MyClassRef");
To copy to clipboard, switch view to plain text mode
it can't be compiled.
and i found the following code works:
bool con = connect(thread, SIGNAL(mysignal3(MyClass)), this, SLOT(myslot3(MyClass)), Qt::BlockingQueuedConnection);
bool con = connect(thread, SIGNAL(mysignal3(MyClass)), this, SLOT(myslot3(MyClass)), Qt::BlockingQueuedConnection);
To copy to clipboard, switch view to plain text mode
here is the code where the thread is created and started:
testsignals
::testsignals(QWidget *parent, Qt
::WFlags flags
){
ui.setupUi(this);
MyThread *thread = new MyThread(this);
qRegisterMetaType<MyClass>();
bool con;
con = connect(thread, SIGNAL(mysignal1(int)), this, SLOT(myslot1(int)), Qt::BlockingQueuedConnection);
con = connect(thread, SIGNAL(mysignal2(MyClass &)), this, SLOT(myslot2(MyClass &)), Qt::BlockingQueuedConnection);
thread->start();
thread->wait();
}
testsignals::testsignals(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);
MyThread *thread = new MyThread(this);
qRegisterMetaType<MyClass>();
bool con;
con = connect(thread, SIGNAL(mysignal1(int)), this, SLOT(myslot1(int)), Qt::BlockingQueuedConnection);
con = connect(thread, SIGNAL(mysignal2(MyClass &)), this, SLOT(myslot2(MyClass &)), Qt::BlockingQueuedConnection);
thread->start();
thread->wait();
}
To copy to clipboard, switch view to plain text mode
and here is the thread's run procedure:
void MyThread::run()
{
emit mysignal1(44);
MyClass m;
emit mysignal2(m);
}
void MyThread::run()
{
emit mysignal1(44);
MyClass m;
emit mysignal2(m);
}
To copy to clipboard, switch view to plain text mode
i know passing stack allocated data by reference isn't good, but just for test...
Bookmarks