Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] "Unavailable synchronous data" when setting variable in object.
Forum Updated to NodeBB v4.3 + New Features

[Solved] "Unavailable synchronous data" when setting variable in object.

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 7.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maxmotor
    wrote on last edited by
    #1

    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_OBJECT

    public 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.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      maxmotor
      wrote on last edited by
      #2

      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!

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        A small yet complete, compilable example would help.

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maxmotor
          wrote on last edited by
          #4

          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!

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            As long as it's solved for you, that's ok :-)

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dcbasso
              wrote on last edited by
              #6

              Can you show some code?!
              I'm having a similar problem, but with some code will help me to find the solution for me!

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved