QObject creating in one thread using in other



  • hi,

    is it possible to create a QObject derived classes and connect the signals in a different thread.

    The QObject loads a plugin in side it. When i try to access the QObject variables in the other thread after releasing the locks on the object, the application is crashing.

    -Sriky



  • Hm, maybe you can provide some sources for better explanation?


  • Moderators

    Passing signals back and forth between threads is thread save, accessing member variables of an object from another thread is not. So your application behaves exactly as expected.



  • Tobias, but simple reading member (without any operatinos from other threads on it) of object from another thread should not crash app.



  • [quote author="Denis Kormalev" date="1287682429"]Tobias, but simple reading member (without any operatinos from other threads on it) of object from another thread should not crash app.[/quote]

    You can you a QMutex to solve the writing part, afair...



  • danilocesar, it is part what I am saying of. As I think author doesn't have race conditions, but has some problems with accessing members. So I think source will be really good to help him.


  • Moderators

    Denis: Sure, but how do you guarantee that no other thread does some writing somewhere without using a mutex or something similar?



  • [quote author="Tobias Hunger" date="1287687383"]Denis: Sure, but how do you guarantee that no other thread does some writing somewhere without using a mutex or something similar?[/quote]

    You don't, however you need to understand/know what your code is doing =)

    I believe we will help better when sriky27 post some code...



  • Tobias, of course there are no guarantee, but I think that question is not about mutexes. Let's wait for authors response.



  • [quote author="Tobias Hunger" date="1287687383"]Denis: Sure, but how do you guarantee that no other thread does some writing somewhere without using a mutex or something similar?[/quote]

    I thought this message was for me =/



  • Hi,

    Thanks for the responses there I am currently stripping my project related content and creating a simple application to present here. To explain what I am doing.

    My objective of creating and starting a new thread was to improve startup of my process, the thread purely constructs an QObject and returns it to the main thread. The thread dies after that.
    I believe I should not have any race conditions there. No one else is trying to access the object.

    -Sriky


  • Moderators

    A commonly used trick to improved perceived startup performance is to create some objects using a singleshot QTimer. That way the complexity of multithreading can be avoided in some cases. Maybe that would be applicable to your setup, too.



  • well i have tried it, i have two objects which take about 2 sec for constructing each of them, i wanted improve on it, so that the objects gets constructed in parallel.

    -Sriky


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.