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. SOLVED - Loop thru QLists?

SOLVED - Loop thru QLists?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 1.7k 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.
  • G Offline
    G Offline
    glowdemon1
    wrote on 11 Apr 2014, 23:10 last edited by
    #1

    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
    0
    • M Offline
      M Offline
      MuldeR
      wrote on 12 Apr 2014, 01:09 last edited by
      #2

      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
      0
      • G Offline
        G Offline
        glowdemon1
        wrote on 12 Apr 2014, 10:43 last edited by
        #3

        [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
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 12 Apr 2014, 12:06 last edited by
          #4

          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
          0
          • X Offline
            X Offline
            Xander84
            wrote on 12 Apr 2014, 14:16 last edited by
            #5

            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
            0

            1/5

            11 Apr 2014, 23:10

            • Login

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