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. Design: relations of classes
Qt 6.11 is out! See what's new in the release blog

Design: relations of classes

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.5k Views 1 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
    pajah
    wrote on last edited by
    #1

    Hi. I've got two classes - MainWindow and Updater (inherited from QObject).

    Option 1:

    • MainWindow calls Updater::checkForUpdates();
    • Updater emits signal if updates are available;
    • MainWindow catches signal and shows corresponding QMessageBox.

    OR option 2:

    • MainWindow calls Updater::checkForUpdates();
    • Updater shows QMessageBox from itself (without a parent, as a consequence).

    The first option allows to easily set MainWindow as a QMessageBox parent.
    But the second one is more logical as an object-oriented design abstraction.

    The overall question: which option is better?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Seba84
      wrote on last edited by
      #2

      I think the first option is more logical from a design patterns point of view as it makes a clear difference between UI objects and others. The QMessageBox being a UI Object it is more logical that it is constructed by the QMainWindow. In that way the Updater only does the updating job and doesn't worries about UI.

      Moreover, I suppose that the comunication back to the QMainWindow is necessary to update also the QMainWindow itself to show data send by the Updater class.

      Hope it helps.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pajah
        wrote on last edited by
        #3

        Seba, your post really clarifies the situation, thanks a lot!

        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