Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    QObject creating in one thread using in other

    Mobile and Embedded
    4
    13
    5450
    Loading More Posts
    • 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.
    • S
      sriky27 last edited by

      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

      1 Reply Last reply Reply Quote 0
      • D
        DenisKormalev last edited by

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

        1 Reply Last reply Reply Quote 0
        • T
          tobias.hunger last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • D
            DenisKormalev last edited by

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

            1 Reply Last reply Reply Quote 0
            • D
              danilocesar last edited by

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

              <a href="http://www.danilocesar.com">Danilo Cesar Lemes de Paula</a>
              Software Engineer

              1 Reply Last reply Reply Quote 0
              • D
                DenisKormalev last edited by

                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.

                1 Reply Last reply Reply Quote 0
                • T
                  tobias.hunger last edited by

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

                  1 Reply Last reply Reply Quote 0
                  • D
                    danilocesar last edited by

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

                    <a href="http://www.danilocesar.com">Danilo Cesar Lemes de Paula</a>
                    Software Engineer

                    1 Reply Last reply Reply Quote 0
                    • D
                      DenisKormalev last edited by

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

                      1 Reply Last reply Reply Quote 0
                      • D
                        danilocesar last edited by

                        [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 =/

                        <a href="http://www.danilocesar.com">Danilo Cesar Lemes de Paula</a>
                        Software Engineer

                        1 Reply Last reply Reply Quote 0
                        • S
                          sriky27 last edited by

                          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

                          1 Reply Last reply Reply Quote 0
                          • T
                            tobias.hunger last edited by

                            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.

                            1 Reply Last reply Reply Quote 0
                            • S
                              sriky27 last edited by

                              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

                              1 Reply Last reply Reply Quote 0
                              • First post
                                Last post