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. [SOLVED] Signal from QList Object to Slot from parent
QtWS25 Last Chance

[SOLVED] Signal from QList Object to Slot from parent

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 5.8k Views
  • 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
    Rocken
    wrote on 5 Apr 2012, 05:26 last edited by
    #1

    I want to relay/concatenate a signal from an object I put into a QList to its parent to trigger a redraw of the parent object. But where to put the connect()?

    @
    void Desktop::addTray(Tray tray) {
    trayList.append(tray);
    }

    void Tray::setColor(int number, QColor color) {
    pointList[number].setColor(color);
    emit dataChanged();
    }
    @

    If I append a new tray object to the desktop I copy the object not a pointer to it. So If I would write the connect() after line 2, I wouldn't connect to the object within the trayList.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Mabrouk
      wrote on 5 Apr 2012, 11:45 last edited by
      #2

      since Tray is QObject subclass, "it can't be copied":http://qt-project.org/doc/qt-4.8/qobject.html#no-copy-constructor-or-assignment-operator
      when you connect, you connect with the original object you created

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Rocken
        wrote on 5 Apr 2012, 12:15 last edited by
        #3

        You're right.. I didn't inherit from QObject. I have to change my QList and store pointers, not objects.
        But how can I prevent that the objects get deleted or freed?
        The Tray-Objects where created dynamically while parsing a file. If the parser function is exited, every Tray object will be deleted or freed.
        How can I prevent them from deletion? I thought on "static" but I want to delete the Tray objects when the QList gets cleared which would be possible with static declaration.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Mabrouk
          wrote on 5 Apr 2012, 12:25 last edited by
          #4

          well this is up to you
          but you can also make the function using references, addTray(Tray &trayObject), this also will work

          1 Reply Last reply
          0
          • R Offline
            R Offline
            Rocken
            wrote on 5 Apr 2012, 12:34 last edited by
            #5

            Oh, you're fast! I edited my last post

            1 Reply Last reply
            0
            • K Offline
              K Offline
              KA51O
              wrote on 5 Apr 2012, 12:46 last edited by
              #6

              create your objects on the heap (using new) not on the stack, this way you have to take care of deleting them and they won't be destroyed when the scope they were created in is closed.

              1 Reply Last reply
              0
              • R Offline
                R Offline
                Rocken
                wrote on 5 Apr 2012, 13:00 last edited by
                #7

                OK thanks, I will rewrite my code and try to put the Trays on the heap and save pointers them in the trayList

                1 Reply Last reply
                0

                2/7

                5 Apr 2012, 11:45

                topic:navigator.unread, 5
                • Login

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