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 QList as a parameter for slot
Forum Updated to NodeBB v4.3 + New Features

Passing QList as a parameter for slot

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 5.0k 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.
  • E Offline
    E Offline
    Exotic_Devel
    wrote on last edited by
    #1

    In my form I have two buttons, each button must be connected to a different slot. And each slot should receive as parameter, the reference to an object QList. eg

    @QList list = new QList();

    void MyClass::save(QList *qlits) // Slot Save
    {
    }

    void MyClass::test(QList *qlist) // Slot test
    {
    }
    @

    How to make the sign of a button "Save" send 'list' reference for the slot 'save' ?

    There are claims that this can be done with QSignalMapper, but the documentation is not very clear on how I can do this.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      arsinte_andrei
      wrote on last edited by
      #2

      maybe @QObject::connect()@ will do it for you.. see the documentation about slot and signal

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

        Hi,

        QSignalMapper won't help you here especially for a QList *. First thing, unless you are modifying your list, there's no reason to pass a pointer to it, use a const reference. Qt's container are implicitly shared so there's no unneeded copy done.

        Depending no where this list comes from, you will have to use an intermediate slot but are you sure you need that ?

        Can you show what you would like to achieve ?

        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
        • E Offline
          E Offline
          Exotic_Devel
          wrote on last edited by
          #4

          This topic is related to another need mentioned in my other "topic":http://qt-project.org/forums/viewthread/46517/.

          Putting it all together, what I need is to catch all QLineEdits of a form and pass to a slot, to be processed. Below my current code

          @Configconnec::Configconnec(QSettings *settings, QObject *parent) : QObject(parent)
          {

          DynamicQtWidgets *dyqtwi = new DynamicQtWidgets(this); // GUI Generator

          QDialog *connecdiag = dyqtwi->createWidget("configconnec.ui");   // Creating GUI
          

          QDialogButtonBox *qdbb_okcancel = connecdiag->findChild("qdbb_okcancel", Qt::FindDirectChildrenOnly);
          QPushButton *qpb_test = connecdiag->findChild("qpb_test", Qt::FindDirectChildrenOnly);

          QList<QLineEdit*> lineedits = connecdiag->findChildren<QLineEdit*>(QString(), Qt::FindDirectChildrenOnly); //Get all lineedits and store in QList

          connect(qdbb_okcancel, SIGNAL(accepted()), this, SLOT(saveParameters()));
          connect(qpb_test, SIGNAL(clicked()), this, SLOT(testParameters()));
          }

          void Configconnec::saveParameters() /Slot to save parameters in disc/
          {
          }

          void Configconnec::testParameters() /Slot to test informed parameters/
          {
          }
          @

          The signal 'accepted' of QDialogButtonBox should send 'lineedits' to 'saveParameters' slot.
          Within saveParameters, QLineEdits objects must be accessed to get content.

          [quote author="SGaist" date="1409602337"]Hi,

          QSignalMapper won't help you here especially for a QList *. First thing, unless you are modifying your list, there's no reason to pass a pointer to it, use a const reference. Qt's container are implicitly shared so there's no unneeded copy done.

          Depending no where this list comes from, you will have to use an intermediate slot but are you sure you need that ?

          Can you show what you would like to achieve ?[/quote]

          1 Reply Last reply
          0
          • A Offline
            A Offline
            arsinte_andrei
            wrote on last edited by
            #5

            Ok. now you have all the QLineEdit in you lineEdits - QList. did you tried something like
            @void Configconnec::saveParameters(){
            for (int var = 0; var < lineEdits.count(); ++var) {
            lineEdits.value(var)->text(); // here you hold the value of each QLineEdit
            /process each value/
            }
            }@

            1 Reply Last reply
            0
            • E Offline
              E Offline
              Exotic_Devel
              wrote on last edited by
              #6

              How to know which QLineEdit will be accessed? Each content will have a different destination, how to know which one I am accessing?

              The saveParameters slot will have access to lineedits? 'lineedit' is in scope of function.
              I would have to make it a class member, and I did not want to do that. In this case, I prefer to leave 'dyqtwi' in class scope. Thus a QList would not be necessary.

              [quote author="arsinte_andrei" date="1409644836"]Ok. now you have all the QLineEdit in you lineEdits - QList. did you tried something like
              @void Configconnec::saveParameters(){
              for (int var = 0; var < lineEdits.count(); ++var) {
              lineEdits.value(var)->text(); // here you hold the value of each QLineEdit
              /process each value/
              }
              }@[/quote]

              1 Reply Last reply
              0
              • A Offline
                A Offline
                arsinte_andrei
                wrote on last edited by
                #7

                you have to have some unique name or some identifier.
                @lineEdits.value(var).objectName@
                try to get the value with @QString objectName() const @ this will return a QString - is unique.

                also set a unique id with
                @void setObjectName(const QString & name)@
                an like that you know what are you writing and where

                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