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. Get a array inside slot
Forum Updated to NodeBB v4.3 + New Features

Get a array inside slot

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 1.7k 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.
  • H Offline
    H Offline
    Helson
    wrote on last edited by Helson
    #1

    Hello, I have a combobox connected on a slot.

    connect(mpCourseComboBox, SIGNAL(currentIndexChanged(int)), &dlgPublicar, SLOT(mySlot(int)));

    I need use the myVector inside the dialog class.

    ClassOne::methodOne{
    QVector<QString> myVector;
    myVector.append("info");
    }
    

    The class below is a dialog with combobox widget

    DialogClass::mySlot(int index){
    //I need get myVector here
    }
    

    I try declare myVector in .h public and

    ClassOne CO;
    co.myVector; //but here it is null
    

    Please.
    Thanks in advance!

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

      Hi

      1. QVector<QString> myVector; will be deleted as soon as methodOne ends.
        you should move it to ClassOne.h as a member of the class;

      2. the combox currentIndexChanged cant take QVector
        so it would be best if dialog already know it.

      So you can add a function to DialogClass to set the list;
      void DialogClass::SetVector(QVector<QString> *Vector) {
      Myvec = Vector ; // keep a pointer to it.
      };

      AND also add a new member variable to DialogClass.h
      QVector<QString> *Myvec=NULL;

      then in DialogClass::mySlot(int index){
      if (Myvec) {
      ....
      }
      }

      // in ClassOne/main
      DialogClass *DC=new DialogClass ();
      DC->SetVector(myVector);

      Note: this is not the best way to do it. it would be via DialogClass constructor as then
      it would have vector from birth.

      H 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi

        1. QVector<QString> myVector; will be deleted as soon as methodOne ends.
          you should move it to ClassOne.h as a member of the class;

        2. the combox currentIndexChanged cant take QVector
          so it would be best if dialog already know it.

        So you can add a function to DialogClass to set the list;
        void DialogClass::SetVector(QVector<QString> *Vector) {
        Myvec = Vector ; // keep a pointer to it.
        };

        AND also add a new member variable to DialogClass.h
        QVector<QString> *Myvec=NULL;

        then in DialogClass::mySlot(int index){
        if (Myvec) {
        ....
        }
        }

        // in ClassOne/main
        DialogClass *DC=new DialogClass ();
        DC->SetVector(myVector);

        Note: this is not the best way to do it. it would be via DialogClass constructor as then
        it would have vector from birth.

        H Offline
        H Offline
        Helson
        wrote on last edited by
        #3

        @mrjj
        Thank you so much!!!

        DC->SetVector(&myVector);
        
        mrjjM 1 Reply Last reply
        1
        • H Helson

          @mrjj
          Thank you so much!!!

          DC->SetVector(&myVector);
          
          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Helson
          Oh I forgot &. good spotted.
          You are welcome.

          1 Reply Last reply
          0
          • H Offline
            H Offline
            Helson
            wrote on last edited by
            #5

            @mrjj
            int size = myVector->size(); //Return 1

            int size = *myVector->size(); //Compilation error

            myVector is an QVector<QVector<QVector<QString>>>

            And it's have some data like:

            QVector(QVector(
            QVector("XXX", "XXX", "XXX", "A") ,
            QVector("XXX", "XXX", "XXX", "B") ,
            QVector("XXX", "XXX", "XXX", "C"),
            QVector("XXX", "XXX", "XXX", "D") ,
            QVector("XXX", "XXX", "XXX", "E") ,
            QVector("XXX", "XXX", "XXX", "F"),
            QVector("XXX", "XXX", "XXX", "G")
            ) )

            And I need iterate...
            if it's not asking too much, can you help me?

            1 Reply Last reply
            1
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi
              it seems like you add a QVector to the QVector.
              And the added QVector, has Many QVectors?
              List of list of list :)
              Can we talk about the data as this is pretty complex to handle :)
              Will each inner list always be the same
              "XXX", "XXX", "XXX", "A"
              "XXX", "XXX", "XXX", "B"
              "XXX", "XXX", "XXX", "C"
              4 strings?

              H 1 Reply Last reply
              0
              • mrjjM mrjj

                Hi
                it seems like you add a QVector to the QVector.
                And the added QVector, has Many QVectors?
                List of list of list :)
                Can we talk about the data as this is pretty complex to handle :)
                Will each inner list always be the same
                "XXX", "XXX", "XXX", "A"
                "XXX", "XXX", "XXX", "B"
                "XXX", "XXX", "XXX", "C"
                4 strings?

                H Offline
                H Offline
                Helson
                wrote on last edited by
                #7

                @mrjj

                The list have another values, but i need this structure to do this.

                myVector[0][0] [0]="XXX" [1]="XXX2", [2]="XXX3" //3dr dimension have the data
                myVector[0][1] [0]="XXX" [1]="XXX2", [2]="XXX3"
                myVector[0][2] ...
                myVector[0][3] ...

                myVector[1][0] ...
                myVector[1][1] ...
                myVector[1][2] ...
                myVector[1][3] ...

                myVector[2][0] ...
                myVector[2][1] ...
                myVector[2][2] ...
                myVector[2][3] ..

                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