Originally Posted by
anda_skoa
In your example both sender and receiver are "this" so if you don't want to copy, why not just have the data as a member?
Still a very strange pattern, maybe some more code would clarify what you are actually trying to do?_
There was a typo in my question (i directly copied from my project code & while changing it I messed up) & here is the simplified code
Ex:
typedef std::vector< std::vector<int> > myData;
qRegisterMetaType<myData>("myData");
class testClass // I want to pass this obj as reference
{
public:
int a;
};
//In my main thread (myclass) : QThread m_thread & workerClass m_worker are the class members & below is constructor code
connect(&m_thread, SIGNAL(started()), this, SLOT(startThread()));
connect(this, SIGNAL(startMyThread(myData&)), &m_worker, SLOT(heavyWork(myData&)));
m_worker.moveToThread(&m_thread);
m_thread.start();
void myclass::startThread()
{
myData obj;
emit startMyThread(obj);
}
Ex:
typedef std::vector< std::vector<int> > myData;
qRegisterMetaType<myData>("myData");
class testClass // I want to pass this obj as reference
{
public:
int a;
};
//In my main thread (myclass) : QThread m_thread & workerClass m_worker are the class members & below is constructor code
connect(&m_thread, SIGNAL(started()), this, SLOT(startThread()));
connect(this, SIGNAL(startMyThread(myData&)), &m_worker, SLOT(heavyWork(myData&)));
m_worker.moveToThread(&m_thread);
m_thread.start();
void myclass::startThread()
{
myData obj;
emit startMyThread(obj);
}
To copy to clipboard, switch view to plain text mode
So here I am getting same error:
QObject::connect: Cannot queue arguments of type 'myData&'
(Make sure 'myData&' is registered using qRegisterMetaType().)
when I make it direct connection (connect(this, SIGNAL(startMyThread(myData&)), &m_worker, SLOT(heavyWork(myData&)), Qt:irectConnection) , the slot is getting executed in the main thread.
i am just looking for a way to pass reference to the thread. i can do it with the pointer as you suggested, But as I am using vector of vector, using pointer to the vector of vector may complicate or confuse or may lead to some memory leaks which I don't want & exactly for the same reason we have reference.
Bookmarks