using qlineedit to read in a string
-
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
-
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
@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