[Solved] "Unavailable synchronous data" when setting variable in object.
-
Hello Qt devs!
I'm currently working on implementing a QThread in my application, to handle some communication. It listens to a com port, and handles incoming data. A part of this routine is that it sets a variable on an object created in my main program thread. I've tried following the example below:
@class Worker : public QObject
{
Q_OBJECTpublic slots:
void doWork() {
/* ... */
}
};/* ... */
QThread *thread = new QThread;
Worker *worker = new Worker;
//obj is a pointer to a QObject that will trigger the work to start. It could just be this
connect(obj, SIGNAL(startWork()), worker, SLOT(doWork()));
worker->moveToThread(thread);
thread->start();
//obj will need to emit startWork() to get the work going.
@
(From "this article":http://http://developer.qt.nokia.com/doc/qt-4.7/qthread.html )
In the doWork() function, I do the actual setting of a variable. This is not possible though. I get an segmentation error saying: "unavailable synchronous data". Is this because I try to change a variable in another thread?Thank you for your time!
Btw Bradley T. Hughes says I'm doing it wrong.
-
Okay, it seems that it has nothing to do with the thread.
I tried running the communication code in the main thread. Again when I try to set the variable in the object, my application crashes. When I check the debugger (using Qt Creator) I see that all the variables in my object has “unavailable synchronous data”.
Any idea what it could be?
Thank you for your time!
-
A small yet complete, compilable example would help.
-
I finally fixed my problem.
Instead of setting the variables directly in my object, I now use a signal and slot to inform my resource class that a variable is updated. This class should handle all my data - creating objects, updating them and so on (I use a Model - View - Controller pattern).
Exactly why it didn't work before I don't know.
It is hard for me to give a small yet complete, compilable example. I hope though this is sufficient information. Else feel free to ask for more information.
Thank you for your time!
-
As long as it's solved for you, that's ok :-)
-
Can you show some code?!
I'm having a similar problem, but with some code will help me to find the solution for me!