Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QT UI multi-thread issue.
Forum Updated to NodeBB v4.3 + New Features

QT UI multi-thread issue.

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
10 Posts 3 Posters 2.6k Views 2 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.
  • T Offline
    T Offline
    TL_Tsai
    wrote on last edited by
    #1

    Hi all ,
    I have a multi-thread process , and use 1 thread to process QT UI . Then I use another thread to render OpenGL Texture .
    Here is a question , sometimes 2 OpenGL(QT UI and OpenGL Texture) will conflict cause broken textures.

    like attaches.
    0_1508144459261_Bug3.png
    this is normal UI ,
    and
    0_1508144502484_Bug4.png
    it broken textures when conflict happens.

    can someone give an answer to fix this issue , or a direction to survey , or go to other Forum.

    Thanks all.
    BR,

    A 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      You should add the version of Qt you are using, the platform you are on and possibly the relevant code sources. It's impossible to give any good answers without knowing what you are currently doing.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      T 2 Replies Last reply
      2
      • T TL_Tsai

        Hi all ,
        I have a multi-thread process , and use 1 thread to process QT UI . Then I use another thread to render OpenGL Texture .
        Here is a question , sometimes 2 OpenGL(QT UI and OpenGL Texture) will conflict cause broken textures.

        like attaches.
        0_1508144459261_Bug3.png
        this is normal UI ,
        and
        0_1508144502484_Bug4.png
        it broken textures when conflict happens.

        can someone give an answer to fix this issue , or a direction to survey , or go to other Forum.

        Thanks all.
        BR,

        A Offline
        A Offline
        ambershark
        wrote on last edited by
        #3

        @TL_Tsai Are you properly protecting memory shared between threads? If you are potentially writing at the same time that will cause issues, usually a crash.

        Make sure you protect your shared memory via mutexes like QMutex.

        My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

        1 Reply Last reply
        1
        • SGaistS SGaist

          Hi and welcome to devnet,

          You should add the version of Qt you are using, the platform you are on and possibly the relevant code sources. It's impossible to give any good answers without knowing what you are currently doing.

          T Offline
          T Offline
          TL_Tsai
          wrote on last edited by
          #4

          @SGaist
          My QT version is 5.9.1 , on Windows and with OpenVR library .
          But about detail codes , I can't tell too much because company's policy.
          Maybe I can show code about how I implement QT in or UI , but need times.

          still thanks your replying.

          1 Reply Last reply
          0
          • SGaistS SGaist

            Hi and welcome to devnet,

            You should add the version of Qt you are using, the platform you are on and possibly the relevant code sources. It's impossible to give any good answers without knowing what you are currently doing.

            T Offline
            T Offline
            TL_Tsai
            wrote on last edited by
            #5

            @SGaist
            hello , there is some codes ,
            I declare QOpenGLContext and QQuickRenderControl and QOpenGLFramebufferObject in my header file
            as below
            QOpenGLContext *qOpenGLContext_;
            QOpenGLFramebufferObject *qOpenglFramebufferObject;
            QQuickRenderControl *qQuickRenderControl_

            and use a timer to call render() periodically

            GLuint render () {
            qQuickRenderControl_->polishItems();
            qQuickRenderControl_->sync();
            qQuickRenderControl_->render();
            GLuint glTexture = qOpenglFramebufferObject->texture();
            qOpenGLContext_->functions()->glFlush();
            return glTexture;
            }

            How do I improve my code? add mutex or...

            thanks for your watching.

            A 1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              That's a bit not enough, you wrote about multiple threads yet here we only have a really small part that might not reflect at all the complexity of your application.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • T TL_Tsai

                @SGaist
                hello , there is some codes ,
                I declare QOpenGLContext and QQuickRenderControl and QOpenGLFramebufferObject in my header file
                as below
                QOpenGLContext *qOpenGLContext_;
                QOpenGLFramebufferObject *qOpenglFramebufferObject;
                QQuickRenderControl *qQuickRenderControl_

                and use a timer to call render() periodically

                GLuint render () {
                qQuickRenderControl_->polishItems();
                qQuickRenderControl_->sync();
                qQuickRenderControl_->render();
                GLuint glTexture = qOpenglFramebufferObject->texture();
                qOpenGLContext_->functions()->glFlush();
                return glTexture;
                }

                How do I improve my code? add mutex or...

                thanks for your watching.

                A Offline
                A Offline
                ambershark
                wrote on last edited by
                #7

                @TL_Tsai From what I see you have shared memory with no mutexing there. qOpenGlContext_, qQuickRenderControl_, and qOpenglFramebufferObject should probably all be mutexed if they are shared between threads.

                Check out QMutex for an easy to use Qt mutex class. You can also use pure c++ mutexes if you'd like. Personally I would go with QMutex since you are already using Qt and it's better. ;)

                My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                T 1 Reply Last reply
                0
                • A ambershark

                  @TL_Tsai From what I see you have shared memory with no mutexing there. qOpenGlContext_, qQuickRenderControl_, and qOpenglFramebufferObject should probably all be mutexed if they are shared between threads.

                  Check out QMutex for an easy to use Qt mutex class. You can also use pure c++ mutexes if you'd like. Personally I would go with QMutex since you are already using Qt and it's better. ;)

                  T Offline
                  T Offline
                  TL_Tsai
                  wrote on last edited by TL_Tsai
                  #8

                  @ambershark
                  My situation is one thread create QOpenGLContext , and one thread create native OpenGLContext .
                  QOpenGLContext use QTs API as I posted , and OpenGLContext use opengl APIs like glGenTextue , glTexImage2d.

                  I'm not sure use mutex can fix this situation or there is conflict between QtOpenGL and native OpenGL originally.

                  A 1 Reply Last reply
                  0
                  • T TL_Tsai

                    @ambershark
                    My situation is one thread create QOpenGLContext , and one thread create native OpenGLContext .
                    QOpenGLContext use QTs API as I posted , and OpenGLContext use opengl APIs like glGenTextue , glTexImage2d.

                    I'm not sure use mutex can fix this situation or there is conflict between QtOpenGL and native OpenGL originally.

                    A Offline
                    A Offline
                    ambershark
                    wrote on last edited by
                    #9

                    @TL_Tsai I had assumed they were created in a single thread and shared.. hmm.

                    I'm not really sure how to help you. Threading issues are the most complicated to solve. It's difficult with knowledge of the project and source code. It's almost impossible without at least source code to look at.

                    I wish I had more advice but the information is just too limited. Good luck though, I'm sure you'll find it. :)

                    My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Why are you mixing both ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      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