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. using qlineedit to read in a string
Forum Updated to NodeBB v4.3 + New Features

using qlineedit to read in a string

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 415 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.
  • pgiovanniP Offline
    pgiovanniP Offline
    pgiovanni
    wrote on last edited by pgiovanni
    #1

    I have this code that creates a very basic QLineEdit box layout. I want to read in from the qlineedit and print out an output somewhere according to another algorithm I've created. I'm not sure how to take in the input. I thought textChanged() would help by emiting the signal and connecting it to my public slot function (which is my algorithm). My current error is no matching member function for call to 'connect'

    #include "window.h"
    
    #include <iostream>
    #include <fstream>
    #include <QComboBox>
    #include <QGridLayout>
    #include <QGroupBox>
    #include <QLabel>
    #include <QLineEdit>
    Window::Window(QWidget *parent) : QWidget(parent) {
    
    QGroupBox *MBTI = new QGroupBox(tr("MBTI"));
       QString *MBTItype;
    
    
       readInMBTI = new QLineEdit;
       readInMBTI->setPlaceholderText("Enter MBTI type and Astrological sign");
       readInMBTI->setFocus();
    
    
    
       QGridLayout *MBTIboxLayout = new QGridLayout;
       MBTIboxLayout->addWidget(readInMBTI, 0, 0);
    
       MBTI->setLayout(MBTIboxLayout);
    
       QGridLayout *layout = new QGridLayout;
    
       layout->addWidget(MBTI, 0, 0);
       setLayout(layout);
    
       *MBTItype = readInMBTI->text();
       connect(*readInMBTI, readInMBTI->textChanged(*MBTItype), this, nextStep(MBTItype->toStdString())); //no matching member function for call to 'connect'
    
    }
    
    void Window::nextStep(std::string MBTI) {/*algo here*/}
    

    window.h :

    #ifndef WINDOW_H
    #define WINDOW_H
    
    #include <QWidget>
    #include <QGroupBox>
    #include <string>
    
    QT_BEGIN_NAMESPACE
    class QLineEdit;
    QT_END_NAMESPACE
    
    //! [0]
    class Window : public QWidget
    {
        Q_OBJECT
    
    public:
        Window(QWidget *parent = nullptr);
    
    public slots:
        void nextStep(std::string);
    
    
    private:
        QLineEdit *readInMBTI;
        QGroupBox *MBTI;
    
    };
    
    
    #endif
    
    jsulmJ 1 Reply Last reply
    0
    • pgiovanniP pgiovanni

      I have this code that creates a very basic QLineEdit box layout. I want to read in from the qlineedit and print out an output somewhere according to another algorithm I've created. I'm not sure how to take in the input. I thought textChanged() would help by emiting the signal and connecting it to my public slot function (which is my algorithm). My current error is no matching member function for call to 'connect'

      #include "window.h"
      
      #include <iostream>
      #include <fstream>
      #include <QComboBox>
      #include <QGridLayout>
      #include <QGroupBox>
      #include <QLabel>
      #include <QLineEdit>
      Window::Window(QWidget *parent) : QWidget(parent) {
      
      QGroupBox *MBTI = new QGroupBox(tr("MBTI"));
         QString *MBTItype;
      
      
         readInMBTI = new QLineEdit;
         readInMBTI->setPlaceholderText("Enter MBTI type and Astrological sign");
         readInMBTI->setFocus();
      
      
      
         QGridLayout *MBTIboxLayout = new QGridLayout;
         MBTIboxLayout->addWidget(readInMBTI, 0, 0);
      
         MBTI->setLayout(MBTIboxLayout);
      
         QGridLayout *layout = new QGridLayout;
      
         layout->addWidget(MBTI, 0, 0);
         setLayout(layout);
      
         *MBTItype = readInMBTI->text();
         connect(*readInMBTI, readInMBTI->textChanged(*MBTItype), this, nextStep(MBTItype->toStdString())); //no matching member function for call to 'connect'
      
      }
      
      void Window::nextStep(std::string MBTI) {/*algo here*/}
      

      window.h :

      #ifndef WINDOW_H
      #define WINDOW_H
      
      #include <QWidget>
      #include <QGroupBox>
      #include <string>
      
      QT_BEGIN_NAMESPACE
      class QLineEdit;
      QT_END_NAMESPACE
      
      //! [0]
      class Window : public QWidget
      {
          Q_OBJECT
      
      public:
          Window(QWidget *parent = nullptr);
      
      public slots:
          void nextStep(std::string);
      
      
      private:
          QLineEdit *readInMBTI;
          QGroupBox *MBTI;
      
      };
      
      
      #endif
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @pgiovanni said in using qlineedit to read in a string:

      connect(*readInMBTI, readInMBTI->textChanged(*MBTItype), this, nextStep(MBTItype->toStdString()));

      This is wrong.
      Please take a look at https://doc.qt.io/qt-5/qlineedit.html#textChanged
      What parameter does it have? Hint: it is not *MBTItype. So, fix your slot (put correct parameter there) and the connect call.
      Also, you can't call anything when doing a connect, I'm referring to this: nextStep(MBTItype->toStdString())
      connect() only connects a signal to a slot, nothing more.
      You also should use new Qt5 connect syntax: https://doc.qt.io/qt-5/signalsandslots.html

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2

      • Login

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