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. Passing messages between objects - alternative to "connect" ?
Forum Updated to NodeBB v4.3 + New Features

Passing messages between objects - alternative to "connect" ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 455 Views 3 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.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by
    #1

    This is kinda of followup on another thread ....

    I am looking for an alternative to pass messages between objects.

    How is this for an idea ?

    Build / create QT "standard " QT Designer Form Class - let's call it "parent class " - for this discussion (only).
    Build / create QT "standard " QT Designer Form Class - let's call it "child class " - for this discussion (only).
    Add the "child class " as a member of the "parent class".

    Both classes have standard Qt form feature, each one accessible from corresponding class.

    Is there a reasonably straight forward way to enable "parent" to access the child form ?

    Ideally the changes in "child " form needs to be passed onto the "parent", and it would not be necessary to actually show the "child" form.

    PS I did try "inheritance" but there in no easy way to inherit /add "form class " to primary form class...

    .

    M 1 Reply Last reply
    0
    • A Anonymous_Banned275

      This is kinda of followup on another thread ....

      I am looking for an alternative to pass messages between objects.

      How is this for an idea ?

      Build / create QT "standard " QT Designer Form Class - let's call it "parent class " - for this discussion (only).
      Build / create QT "standard " QT Designer Form Class - let's call it "child class " - for this discussion (only).
      Add the "child class " as a member of the "parent class".

      Both classes have standard Qt form feature, each one accessible from corresponding class.

      Is there a reasonably straight forward way to enable "parent" to access the child form ?

      Ideally the changes in "child " form needs to be passed onto the "parent", and it would not be necessary to actually show the "child" form.

      PS I did try "inheritance" but there in no easy way to inherit /add "form class " to primary form class...

      .

      M Offline
      M Offline
      mpergand
      wrote on last edited by mpergand
      #2

      @AnneRanch said in Passing messages between objects - alternative to "connect" ?:

      I am looking for an alternative to pass messages between objects.

      You can use custom event,
      Define your own events and send them with:
      [static] bool QCoreApplication::sendEvent(QObject *receiver, QEvent *event)

      Sends event event directly to receiver receiver, using the notify() function. Returns the value that was returned from the event handler.
      The event is not deleted when the event has been sent. The normal approach is to create the event on the stack, for example:
      QMouseEvent event(QEvent::MouseButtonPress, pos, 0, 0, 0);
      QApplication::sendEvent(mainWindow, &event);

      @AnneRanch said in Passing messages between objects - alternative to "connect" ?:

      Is there a reasonably straight forward way to enable "parent" to access the child form ?

      Yes, include the ui_childName.h and in child class add a get method:
      UI::ChildName* childUi() { return ui; }
      some will say it's bad practice bla bla, it's up to you to decide :)

      The other way is to retreive each object by name:
      child->findChild<SomeClass*>("objectName")

      Of course, the "normal/right way" is to define getters for all the objects you need,
      but it is borring I know ;)

      1 Reply Last reply
      0
      • Kent-DorfmanK Offline
        Kent-DorfmanK Offline
        Kent-Dorfman
        wrote on last edited by
        #3

        the answer the question based on post title, there are many possibilities to have "objects" communicate with each other but why reinvent the wheel? anything custom will need to be rigorously proven, especially with regard to object syncronization. the signal/slot mechanism already takes care of the heavy lifting. The only time I'd entertain a custom object communications channel would be when IPC (interprocess communications) is necessary, or processes/objects running in their own address space...and then I'd try to choose a high level API that already exists: message queues, fifos, sockets, etc.

        I light my way forward with the fires of all the bridges I've burned behind me.

        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