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. Executing QDialog from a class inherited from QObject
Forum Updated to NodeBB v4.3 + New Features

Executing QDialog from a class inherited from QObject

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 665 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.
  • R Offline
    R Offline
    Radim
    wrote on last edited by Radim
    #1

    Hi,

    I have an Program class, which inherits from Engine, which inherits from QObject. The Engine class do some processing. The processing is started using a bool run() method implemented in the Program class. It returns true if it has been started or false if it failed. The error string can be read via QString errorString() method. When the processing is finished, the class sends a signal.

    Now I need to ask the user in the run() method whether to ignore some error and continue or quit. I know that I cannot inherit the Program from both Engine (aka QObject) and QWidget.

    The Program class is constructed using QWidgetparent object. Is it a good idea to cast this object in the run() method to initialize a QDialog (so it appears in the middle of the main window)?

    QDialog *dialog = new QDialog(qobject_cast<QWidget*>(this));

    Or should I use a different approach to ask a user from within a class inherited from QObject?

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

      Hi,

      Yes, you should use a different approach. The first thing to think about is: does it really make sense to have the dialog handling in that object ? Should it be the responsibility of e.g. the main window ? Like Program sending a signal for more inputs and main window get them before sending them to Program. Then the second thing is: will Program be used in a different thread ? If so, then you can't run GUI related stuff in a thread that is not the main thread a.k.a the GUI 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

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved