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
QtWS25 Last Chance

Loading QStringList value received from signal slot

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtcreatorsignal & slotconstructorcombobox
6 Posts 4 Posters 2.9k 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.
  • L Offline
    L Offline
    Lasith
    wrote on last edited by Lasith
    #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 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
      4
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on 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
        2
        • M mostefa

          @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 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
          • SGaistS SGaist

            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 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
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on 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

              • Login

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