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. How to change values of a QList<QString> using QDialog

How to change values of a QList<QString> using QDialog

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 864 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.
  • F Offline
    F Offline
    frnklu20
    wrote on last edited by
    #1

    I'm using a QDialog with 4 QLineEdits

    what i want is to take the text in these qlineEdit and change the values of each item of my Qlist

    equipamentos.h

    class BarramDialog : public QDialog
    {
        Q_OBJECT
    
    public:
        explicit BarramDialog(QWidget *parent = nullptr);
        ~BarramDialog();
    
        QString nome_dialog(QString &);
        void setdata(QList<QString>&);
        QList<QString> data=QList<QString>() <<"pegadinha"<<""<<""<<"";
    
    private slots:
    
        void on_ok_button_clicked();
    
    private:
        Ui::BarramDialog *ui;
        void changevalues(int i, QString value);
    

    barramento.cpp

    BarramDialog::BarramDialog(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::BarramDialog)
    {
        ui->setupUi(this);
        ui->name_line->setText(data[0]);
        ui->num_line->setText(data[1]);
        ui->v_line->setText(data[2]);
        ui->ang_line->setText(data[3]);
    
    }
    
    BarramDialog::~BarramDialog()
    {
        delete ui;
    }
    
    void BarramDialog::setdata(QList<QString> &new_list)
    {
        ui->name_line->setText(new_list[0]);
        ui->num_line->setText(new_list[1]);
        ui->v_line->setText(new_list[2]);
        ui->ang_line->setText(new_list[3]);
        update();
    }
    
    
    
    
    void BarramDialog::on_ok_button_clicked()
    {
    
        QMessageBox::StandardButton resposta=QMessageBox::question(this,"","Deseja salvar esses parametros?",QMessageBox::Yes|QMessageBox::No);
        if(resposta==QMessageBox::Yes)
        {
            data[0]=ui->name_line->text();
            data[1]=ui->num_line->text();
            data[2]=ui->v_line->text();
            data[3]=ui->ang_line->text();
            
            
            changevalues(0,ui->name_line->text());
            changevalues(1,ui->num_line->text());
            changevalues(2,ui->v_line->text());
            changevalues(3,ui->ang_line->text());
            
            this->close();
    
        }
    }
    
    void BarramDialog::changevalues(int i, QString value)
    {
        data[i]=value;
    }
    

    i did this but the values in the Qlist are not updated
    how can I fix it?

    J.HilkJ 1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @frnklu20 said in How to change values of a QList<QString> using QDialog:

      i did this but the values in the Qlist are not updated

      In which list? How do you check?
      And why do you do things twice?

      data[0]=ui->name_line->text();
      changevalues(0,ui->name_line->text());

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • Kent-DorfmanK Offline
        Kent-DorfmanK Offline
        Kent-Dorfman
        wrote on last edited by Kent-Dorfman
        #3

        @frnklu20 said in How to change values of a QList<QString> using QDialog:

        QList<QString> data=QList<QString>() <<"pegadinha"<<""<<""<<"";

        First...don't do this. It is ugly! Separate the container constructor from pushing values into it.

        I would argue that you should use a QMap so that each element being returned from your UI has a unique key associated with it and they are NOT position dependent within the QList.

        Finally, if I had to WAG (without testing) I'd guess that the constructor is the reason your list is failing. After calling the exact line you entered above, check data.size() and see what it says. Perhaps is is NOT actually four elements long?

        If you meet the AI on the road, kill it.

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Kent-Dorfman said in How to change values of a QList<QString> using QDialog:

          Perhaps is is NOT actually four elements long?

          It is - otherwise the compiler would be wrong.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0
          • F frnklu20

            I'm using a QDialog with 4 QLineEdits

            what i want is to take the text in these qlineEdit and change the values of each item of my Qlist

            equipamentos.h

            class BarramDialog : public QDialog
            {
                Q_OBJECT
            
            public:
                explicit BarramDialog(QWidget *parent = nullptr);
                ~BarramDialog();
            
                QString nome_dialog(QString &);
                void setdata(QList<QString>&);
                QList<QString> data=QList<QString>() <<"pegadinha"<<""<<""<<"";
            
            private slots:
            
                void on_ok_button_clicked();
            
            private:
                Ui::BarramDialog *ui;
                void changevalues(int i, QString value);
            

            barramento.cpp

            BarramDialog::BarramDialog(QWidget *parent) :
                QDialog(parent),
                ui(new Ui::BarramDialog)
            {
                ui->setupUi(this);
                ui->name_line->setText(data[0]);
                ui->num_line->setText(data[1]);
                ui->v_line->setText(data[2]);
                ui->ang_line->setText(data[3]);
            
            }
            
            BarramDialog::~BarramDialog()
            {
                delete ui;
            }
            
            void BarramDialog::setdata(QList<QString> &new_list)
            {
                ui->name_line->setText(new_list[0]);
                ui->num_line->setText(new_list[1]);
                ui->v_line->setText(new_list[2]);
                ui->ang_line->setText(new_list[3]);
                update();
            }
            
            
            
            
            void BarramDialog::on_ok_button_clicked()
            {
            
                QMessageBox::StandardButton resposta=QMessageBox::question(this,"","Deseja salvar esses parametros?",QMessageBox::Yes|QMessageBox::No);
                if(resposta==QMessageBox::Yes)
                {
                    data[0]=ui->name_line->text();
                    data[1]=ui->num_line->text();
                    data[2]=ui->v_line->text();
                    data[3]=ui->ang_line->text();
                    
                    
                    changevalues(0,ui->name_line->text());
                    changevalues(1,ui->num_line->text());
                    changevalues(2,ui->v_line->text());
                    changevalues(3,ui->ang_line->text());
                    
                    this->close();
            
                }
            }
            
            void BarramDialog::changevalues(int i, QString value)
            {
                data[i]=value;
            }
            

            i did this but the values in the Qlist are not updated
            how can I fix it?

            J.HilkJ Online
            J.HilkJ Online
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @frnklu20 where exactly do you check, that the list was updated ? I can't see that from the code you posted


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            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