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. Thread with MDISubWindow
Forum Updated to NodeBB v4.3 + New Features

Thread with MDISubWindow

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 5 Posters 506 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.
  • P Offline
    P Offline
    pixbyte
    wrote on last edited by
    #1

    I try to use a Thread inside my MDISubWindow to process data collection. I added the thread to the MDISubWindow class:

    class ThreadHex : public QThread
    {
        Q_OBJECT
    public:
        ThreadHex(){}
    protected:
        void run();
    
    };
    
    class MdiChildHex : public MdiChildBase
    {
        Q_OBJECT
        friend class ThreadHex;
    
    public:
        MdiChildHex(QWidget* parent, const QString &device);
    
    protected:
        ThreadHex *mMyThread;
    };
    

    Now I try to use the MdiChildHex as reference inside the Thread, but QT will tell me that it do not know MdiChildHex inside the thread.

    class ThreadHex : public QThread
    {
        Q_OBJECT
    public:
        ThreadHex( MdiChildHex *hTest){ kTest = hTest;}
    protected:
        void run();
        MdiChildHex *kTest;
    
    };
    
    Anybody can give me a hint what I do wrong to add a Thread to the MdiSubWindow?
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Before going further, are trying to modify the Mdi subwindow in the thread ?

      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
      • P Offline
        P Offline
        pixbyte
        wrote on last edited by
        #3

        No. I have some operations to read from DVD that are blocking the MIDSubWindow to show. So I want to move them to the thread.

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

          So why would your thread need to know anything about the Mdi sub-window ?

          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
          3
          • P Offline
            P Offline
            pixbyte
            wrote on last edited by
            #5

            I wanto to:
            a.) Read values from window
            b.) Call a function from the MdiSubWindows (Share function) to avoid to write double code.

            Inside a subclassed Treewidget It was no problem but here I get always the unknown error. That why I asked if there is anything different with QMDISubWindow and as sample a custom QTreeWidget inside a QMDISubWindow.

            jsulmJ 1 Reply Last reply
            0
            • P pixbyte

              I wanto to:
              a.) Read values from window
              b.) Call a function from the MdiSubWindows (Share function) to avoid to write double code.

              Inside a subclassed Treewidget It was no problem but here I get always the unknown error. That why I asked if there is anything different with QMDISubWindow and as sample a custom QTreeWidget inside a QMDISubWindow.

              jsulmJ Online
              jsulmJ Online
              jsulm
              Lifetime Qt Champion
              wrote on last edited by jsulm
              #6

              @pixbyte Your DVD thread should not know anything about MIDSubWindow. It should only read the data and emit a signal to transfer the data from DVD. MIDSubWindow can then connect a slot to that signal and do whatever needs to be done.

              Only GUI thread (the one where app.exec() was called) is allowed to access UI elements!

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              3
              • P Offline
                P Offline
                pixbyte
                wrote on last edited by
                #7

                Why you cannot just answer my question or give me a hint about the problem? To tell public to write code two or three times is not trustfully. I use many threads in my custom widgets and I share many functions inside the software, this is the ground base of unit testing and DevOps.
                The problem I have is about the MDISUb, so anybody here who can tell me something about this?

                J.HilkJ 1 Reply Last reply
                0
                • P pixbyte

                  Why you cannot just answer my question or give me a hint about the problem? To tell public to write code two or three times is not trustfully. I use many threads in my custom widgets and I share many functions inside the software, this is the ground base of unit testing and DevOps.
                  The problem I have is about the MDISUb, so anybody here who can tell me something about this?

                  J.HilkJ Offline
                  J.HilkJ Offline
                  J.Hilk
                  Moderators
                  wrote on last edited by J.Hilk
                  #8

                  @pixbyte
                  You most likely forgot to

                  #include <QMdiSubWindow>
                  or 
                  #include <MdiChildHex>
                  or
                  #include "MdiChildHex.h"
                  //or something similar
                  

                  but seriously, you approach is wrong from the ground up.


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

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

                    @J-Hilk You forgot one thing: if these two classes are in separate files, there's now going to be a circular referencing error.

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

                    J.HilkJ 1 Reply Last reply
                    2
                    • SGaistS SGaist

                      @J-Hilk You forgot one thing: if these two classes are in separate files, there's now going to be a circular referencing error.

                      J.HilkJ Offline
                      J.HilkJ Offline
                      J.Hilk
                      Moderators
                      wrote on last edited by
                      #10

                      @SGaist
                      very true, where we would be back at the beginning,right with:

                      Why should the QThread based class know anything about any QWidget in the first place?


                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                      Q: What's that?
                      A: It's blue light.
                      Q: What does it do?
                      A: It turns blue.

                      1 Reply Last reply
                      1
                      • mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by mrjj
                        #11

                        Hi
                        There is nothing special about QMDISubWindow and threads but same rules apply as with any widget that its state should be only be altered in main thread.

                        • that it do not know MdiChildHex inside the thread.

                        Well if you have include the right include file and it still says its unknown
                        then check
                        as mention if you have a circular includes
                        ( a includes b and b includes a)
                        That also gives unknown type error.

                        The normal fix can be in to use a class forward in the
                        ThreadHex class .h since you use a pointer to the type
                        class MdiChildHex; // forward
                        and have the real include in the .cpp instead.

                        Also as mentioned by the other , the optimal design is to use signal and slot for an implementation that is less coupled.

                        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