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. No matching function?
Forum Updated to NodeBB v4.3 + New Features

No matching function?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.5k 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.
  • G Offline
    G Offline
    glowdemon1
    wrote on last edited by
    #1

    Hi, I'm trying to create a program and I'm currently working on a function that turns a checkbox off if the line-edit next to it is empty but it toggles it on when it's not empty. I have this weird error :

    @C:\Users\Robbe\Desktop\C++\workspace\mta\mainwindow.cpp:30: error: no matching function for call to 'MainWindow::toggleCheckBox(QCheckBox*&, QLineEdit*&)'
    MainWindow::toggleCheckBox(ui->checkBoxCreateServerFile,ui->lineEditCreateServerFile);
    ^@

    @#include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "QCheckBox"
    #include "QString"
    #include "QLineEdit"

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

    void MainWindow::toggleCheckBox(QCheckBox checkBox,QLineEdit lineEdit){
    QString text = lineEdit.text();
    if(text == ""){
    checkBox.setChecked(false);
    }else{
    checkBox.setChecked(true);
    }
    }

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

    void MainWindow::on_lineEditCreateServerFile_textEdited()
    {
    MainWindow::toggleCheckBox(ui->checkBoxCreateServerFile,ui->lineEditCreateServerFile);
    }
    void MainWindow::on_lineEditCreateClientFile_textEdited()
    {
    MainWindow::toggleCheckBox(ui->checkBoxCreateClientFile,ui->lineEditCreateClientFile);
    }
    @

    Here's my header :

    @#ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    #include "QCheckBox"
    #include "QLineEdit"

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    void toggleCheckBox(QCheckBox checkBox,QLineEdit lineEdit);
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    private slots:
    void on_lineEditCreateServerFile_textEdited();

    void on_lineEditCreateClientFile_textEdited();
    

    private:
    Ui::MainWindow *ui;
    };

    #endif // MAINWINDOW_H
    @

    Also is there a way to make this easier? Because I have like 10 line-edits I have to call this function on? I'm talking about creating some kind of general event checker because I'm not really interested in writing all of those slots like this @void MainWindow::on_lineEditCreateClientFile_textEdited()
    {
    MainWindow::toggleCheckBox(ui->checkBoxCreateClientFile,ui->lineEditCreateClientFile);
    }@

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      @void toggleCheckBox(QCheckBox checkBox,QLineEdit lineEdit);@

      Take objects and your giving it pointers. Note that you can't copy QObject and QObject derived classes.

      Update the signature to that

      @void toggleCheckBox(QCheckBox *checkBox,QLineEdit *lineEdit);@

      And reimplement the function accordingly.

      Also, you call it like a static function which it is not.

      Hope it helps

      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
      • G Offline
        G Offline
        glowdemon1
        wrote on last edited by
        #3

        [quote author="SGaist" date="1397249905"]Hi,

        @void toggleCheckBox(QCheckBox checkBox,QLineEdit lineEdit);@

        Take objects and your giving it pointers. Note that you can't copy QObject and QObject derived classes.

        Update the signature to that

        @void toggleCheckBox(QCheckBox *checkBox,QLineEdit *lineEdit);@

        And reimplement the function accordingly.

        Also, you call it like a static function which it is not.

        Hope it helps[/quote]

        Thank you.

        1 Reply Last reply
        0
        • X Offline
          X Offline
          Xander84
          wrote on last edited by
          #4

          Hi, if you have many of those check box and line edit combination you could create a custom QWidget and reuse that maybe, I don't know how well that works with the designer (maybe not that good).
          If you want to keep it simple you could at least add a generic function that takes a QCheckBox and QLineEdit and do your "property binding" in there, so you can call this function for all your combination but only have to define the code once at least.

          example:
          @
          void MainWindow::connectCheckBoxToLineEdit(QCheckBox *cb, QLineEdit *le)
          {
          connect(le, &QLineEdit::textChanged, [cb](const QString &text) {
          cb->setEnabled(!text.isEmpty());
          });
          }
          @
          you only have to define that function once, in that example I have connected the textChanged signal of the line edit to the check box, so every time the text changes the expression is evaluated and the check box is only enabled if the line edit contains text.
          you can use that function like this:
          @
          connectCheckBoxToLineEdit(ui->checkBox, ui->lineEdit);
          connectCheckBoxToLineEdit(ui->checkBox2, ui->lineEdit2);
          ...
          @
          I've used an anonymous slot with a c++ lambda function there, hope that helps and doesn't confuse you :)

          1 Reply Last reply
          0
          • G Offline
            G Offline
            glowdemon1
            wrote on last edited by
            #5

            [quote author="Xander84" date="1397251136"]Hi, if you have many of those check box and line edit combination you could create a custom QWidget and reuse that maybe, I don't know how well that works with the designer (maybe not that good).
            If you want to keep it simple you could at least add a generic function that takes a QCheckBox and QLineEdit and do your "property binding" in there, so you can call this function for all your combination but only have to define the code once at least.

            example:
            @
            void MainWindow::connectCheckBoxToLineEdit(QCheckBox *cb, QLineEdit *le)
            {
            connect(le, &QLineEdit::textChanged, [cb](const QString &text) {
            cb->setEnabled(!text.isEmpty());
            });
            }
            @
            you only have to define that function once, in that example I have connected the textChanged signal of the line edit to the check box, so every time the text changes the expression is evaluated and the check box is only enabled if the line edit contains text.
            you can use that function like this:
            @
            connectCheckBoxToLineEdit(ui->checkBox, ui->lineEdit);
            connectCheckBoxToLineEdit(ui->checkBox2, ui->lineEdit2);
            ...
            @
            I've used an anonymous slot with a c++ lambda function there, hope that helps and doesn't confuse you :)[/quote]

            Mhhh.. Seems a better way to do it indeed.

            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