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. Loading QStringList value received from signal slot
Forum Updated to NodeBB v4.3 + New Features

Loading QStringList value received from signal slot

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtcreatorsignal & slotconstructorcombobox
6 Posts 4 Posters 2.9k 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.
  • L Offline
    L Offline
    Lasith
    wrote on 2 Dec 2017, 18:15 last edited by Lasith 12 Feb 2017, 18:19
    #1

    In my qt c++ application a QStringList is sent from one cpp file(MainWIndow) to another cpp file(Dialog) via signal and slots mechanism! I want to display the elements in the qtringList on a combo box in the Dialog.ui when the interface gets loaded(no button click)!

    following is my code

    #include "dialog.h"
    #include "ui_dialog.h"

    Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
    {
    ui->setupUi(this);

    for(int i=0;i<subMessages.size();i++){
    ui->comboBox->addItem(subMessages[i]);

    }
    

    }

    void Dialog::receiveSubMessages(QStringList List){
    subMessages=List;

    }

    The QStringList is received successfully through the slot(already verified).Though I used a for loop and tried display (as in the code) nothing was displayed on the combo box! How can I fix this issue?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mostefa
      wrote on 2 Dec 2017, 19:29 last edited by
      #2

      @Lasith said in Loading QStringList value received from signal slot:

      The QStringList is received successfully through the slot(already verified).

      Hi @Lasith

      The receiveSubMessages(QStringList List) is called after the construction of your Dialog , Every time you try to add an item on your comboxBox your List is empty ,

      Can you share the other parts of your code ?

      Maybe you just wanna have another argument on your Dialog constructor ?

      For example:

      Dialog::Dialog(QStringList listToLoad, QWidget *parent = 0) ;
      
      L 1 Reply Last reply 3 Dec 2017, 02:40
      4
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 2 Dec 2017, 20:34 last edited by
        #3

        Hi,

        To add to @mostefa, if you want to update your combo box, you should first clear it and the call the QComboBox::addItems method. This will avoid that unnecessary loop.

        Note that you should also pass your QStringList as const reference, that will avoid an unnecessary copy.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        L 1 Reply Last reply 3 Dec 2017, 02:56
        2
        • M mostefa
          2 Dec 2017, 19:29

          @Lasith said in Loading QStringList value received from signal slot:

          The QStringList is received successfully through the slot(already verified).

          Hi @Lasith

          The receiveSubMessages(QStringList List) is called after the construction of your Dialog , Every time you try to add an item on your comboxBox your List is empty ,

          Can you share the other parts of your code ?

          Maybe you just wanna have another argument on your Dialog constructor ?

          For example:

          Dialog::Dialog(QStringList listToLoad, QWidget *parent = 0) ;
          
          L Offline
          L Offline
          Lasith
          wrote on 3 Dec 2017, 02:40 last edited by
          #4

          @mostefa Thanx these are the only parts in my Dialog.cpp file! After I put th QStringList as an argument I get an error stating "Prototype for Dialog does not match any in class Dialog".

          1 Reply Last reply
          0
          • S SGaist
            2 Dec 2017, 20:34

            Hi,

            To add to @mostefa, if you want to update your combo box, you should first clear it and the call the QComboBox::addItems method. This will avoid that unnecessary loop.

            Note that you should also pass your QStringList as const reference, that will avoid an unnecessary copy.

            L Offline
            L Offline
            Lasith
            wrote on 3 Dec 2017, 02:56 last edited by
            #5

            @SGaist Thanx my combo box is empty from the beginning I just want to load the QStringList contents to it! :(

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 3 Dec 2017, 09:04 last edited by
              #6

              Hi
              If you changed to
              Dialog::Dialog(QStringList listToLoad, QWidget *parent = 0) ;

              Make sure to change it both in .h file and .cpp file so they match.

              1 Reply Last reply
              0

              5/6

              3 Dec 2017, 02:56

              • Login

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