Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    SOLVED - Loop thru QLists?

    General and Desktop
    4
    5
    1415
    Loading More Posts
    • 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.
    • G
      glowdemon1 last edited by

      Hi, so I have a function that I need to call of every line edit and checkbox. I tried to do it myself but failed a bit and need some help. This is what I got :

      ps. The amount of line edits and checkboxes are equal.
      @#include "mainwindow.h"
      #include "ui_mainwindow.h"
      #include "QCheckBox"
      #include "QString"
      #include "QLineEdit"
      #include "QListIterator"

      void connectCheckBoxToLineEdit(QCheckBox *cb, QLineEdit *le);

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

      QList<QLineEdit> *lineEdits = ui->centralWidget->findChildren<QLineEdit();
      QList<QCheckBox> *checkBoxes = ui->centralWidget->findChildren<QCheckBox>();
      for(int i=0; i<=lineEdits.size(); i++){
          connectCheckBoxToLineEdit();
      }
      

      }

      MainWindow::~MainWindow()
      {
      delete ui;
      }

      void MainWindow::connectCheckBoxToLineEdit(QCheckBox *cb, QLineEdit *le)
      {
      connect(le, &QLineEdit::textChanged, [cb](const QString &text) {
      cb->setEnabled(!text.isEmpty());
      });
      }

      void MainWindow::on_pushButton_clicked()
      {
      //SELECT DIRECTORY
      }

      void MainWindow::on_pushButtonOutput_clicked()
      {
      //GENERATE FILES
      }@

      1 Reply Last reply Reply Quote 0
      • M
        MuldeR last edited by

        Your connectCheckBoxToLineEdit() function takes two parameters, but then you try to call it without any arguments?

        @for(int i=0; i<=lineEdits.size(); i++){
        connectCheckBoxToLineEdit();
        }@

        What about this:
        @const int len = qMin(checkBoxes.size(), lineEdits.size());
        for(int i=0; i <= len; i++)
        {
        connectCheckBoxToLineEdit(checkBoxes[i], lineEdits[i]);
        }@

        My OpenSource software at: http://muldersoft.com/

        Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

        Go visit the coop: http://youtu.be/Jay...

        1 Reply Last reply Reply Quote 0
        • G
          glowdemon1 last edited by

          [quote author="MuldeR" date="1397264982"]Your connectCheckBoxToLineEdit() function takes two parameters, but then you try to call it without any arguments?

          @for(int i=0; i<=lineEdits.size(); i++){
          connectCheckBoxToLineEdit();
          }@

          What about this:
          @const int len = qMin(checkBoxes.size(), lineEdits.size());
          for(int i=0; i <= len; i++)
          {
          connectCheckBoxToLineEdit(checkBoxes[i], lineEdits[i]);
          }@[/quote]

          Just did it as an example.

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            Hi,

            Then what has failed ?

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

            1 Reply Last reply Reply Quote 0
            • X
              Xander84 last edited by

              seems like you are using the findChildren method a little bit wrong?
              change
              @
              QList<QLineEdit> lineEdits = ui->centralWidget->findChildren<QLineEdit();
              @
              to
              @
              QList<QLineEdit
              > lineEdits = ui->centralWidget->findChildren<QLineEdit*>();
              @

              Also you have defined "connectCheckBoxToLineEdit" as a global function but then declare it as a member function of MainWindow. Maybe read some c++ book or tutorials first to learn the basics of c++, just saying you have some weird errors in that code.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post