Get a array inside slot

  • 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.

    QVector<QString> myVector;

    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

    Thanks in advance!

  • Qt Champions 2017


    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 ();

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

  • @mrjj
    Thank you so much!!!


  • Qt Champions 2017

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

  • @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("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?

  • Qt Champions 2017

    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?

  • @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] ..

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.