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. QThread in MainWindow
Forum Updated to NodeBB v4.3 + New Features

QThread in MainWindow

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 1.7k 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.
  • O Offline
    O Offline
    ondra
    wrote on last edited by
    #1

    Hi all,
    I'm trying to write a program for a sound visualization. I want to process reading of samples from a soundcard in one thread and plotting the data in another thread. However, when I want to inherit from QThread in MainWindow, I get an error. So I tried to write another class for plotting to walk around the error from inheriting. But I also get a new error when I try to access ui object outside of MainWindow. What would be a solution to this problem?

    Thank you in advance for your response :)

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

      Hi and welcome to devnet,

      If I understand you correctly you are trying to do something like:

      class MyWindow : public QThread, QMainWindow
      

      Then you can't. You can't create a subclass from two QObject derived class.

      Anyway, you are trying to mix two things that shouldn't be. Keep responsibilities separated. Do the audio processing in the thread and then use signals and slots to propagate updates to your GUI. That has the added benefit of letting you freely change the GUI without having to rewrite the processing part. You can take some inspiration on e.g. the mandelbrot example for that.

      Hope it helps

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

        Thank you so much for your reply SGaist. It helped a lot. I just need to get one more thing clarified. Right now, I am creating an additional thread using my class for audio processing. So that means that I have two threads: the one that deals with the visualization and the one that records the samples. But in my project, I would like to be able to visualize the amplitude and the spectrum at the same time. It means that I will need to update at least two graphic windows in real time. So in addition to what SGaist replied, there is no way in Qt how to separate multiple visualizations into multiple threads when the visualizations happen in a MainWindow?

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

          Have a custom widget for each visualization part and connect them to the corresponding thread. Then put these widgets in your MainWindow e.g. each one in a QDockWidget

          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