QPointerEvent throws error
-
@curiosity Well, then compile.
Code model can produce false errors in QtCreator. -
i am trying to print the edited text(values entered by the user) onto the console. but still getting this error
SIGNAL(&QLineEdit::textEdited)
really?
You should read the Qt signals and slot documentation and also re-read the wiki page which @jsulm already pointed you to.
-
SIGNAL(&QLineEdit::textEdited)
really?
You should read the Qt signals and slot documentation and also re-read the wiki page which @jsulm already pointed you to.
connect(echoComboBox, &QComboBox::editTextChanged(echoLineEdit), this, [=](const QString &edited){qDebug() << edited;});
i made the above change. but signal is giving error
"call to non static function without an object argument". editTextChanged has qstring . i tried with qsting and qlineEdit as arg. its giving same error with both -
connect(echoComboBox, &QComboBox::editTextChanged(echoLineEdit), this, [=](const QString &edited){qDebug() << edited;});
i made the above change. but signal is giving error
"call to non static function without an object argument". editTextChanged has qstring . i tried with qsting and qlineEdit as arg. its giving same error with both@curiosity Please read the documentation! What you're doing is simply wrong and not even valid C++!
You do not pass parameters when calling connect! Parameters are passed to the signal when it is emitted and then from the signal to slot.connect(echoComboBox, &QComboBox::editTextChanged, this, [=](const QString &edited){qDebug() << edited;});
-
@curiosity Please read the documentation! What you're doing is simply wrong and not even valid C++!
You do not pass parameters when calling connect! Parameters are passed to the signal when it is emitted and then from the signal to slot.connect(echoComboBox, &QComboBox::editTextChanged, this, [=](const QString &edited){qDebug() << edited;});
thanks for correcting.
i am trying to echo the text entered by the user into QCombobox in the next line.
connect(echoComboBox, &QComboBox::currentTextChanged,this, &Window::onCurrentTextChanged);
auto text = echoComboBox->currentText(); passwordLineEdit = new QLineEdit; passwordLineEdit->setPlaceholderText("Password entered is : "); //But this line is displayed in a new window. and password is not echoed.
passwordLineEdit->show();
echoComboBox->show();
-
thanks for correcting.
i am trying to echo the text entered by the user into QCombobox in the next line.
connect(echoComboBox, &QComboBox::currentTextChanged,this, &Window::onCurrentTextChanged);
auto text = echoComboBox->currentText(); passwordLineEdit = new QLineEdit; passwordLineEdit->setPlaceholderText("Password entered is : "); //But this line is displayed in a new window. and password is not echoed.
passwordLineEdit->show();
echoComboBox->show();
@curiosity said in QPointerEvent throws error:
//But this line is displayed in a new window
You have created a
new QLineEdit
but not put it anywhere (e.g. on an existing window), so where do you expect it to go? I do not know why you are choosing to create a newQLineEdit
dynamically, but give it a parent and/or place it on some widget's layout.I really don't know what you are doing with a combobox."i am trying to echo the text entered by the user into QCombobox" --- what text is being entered how by user into combobox. Why in the world would you have a combobox, to choose an existing item from, if you want a user to enter a line of text for a password?
passwordLineEdit->setPlaceholderText("Password entered is : "); //But this line is displayed in a new window. and password is not echoed.
"Password is not echoed", what do you mean or expect? All you have done here is set the placeholder text of a
QLineEdit
to a fixed string. I see nothing in your code which perhaps copes/displays theauto text = echoComboBox->currentText();
anywhere.@jsulm gave you sample code for picking up changed edited text. All you have to do is change his lambda slot to (preferably using his signal) to call a method of you own, like you show with
&Window::onCurrentTextChanged
, and write the code in that to access the current text or thetext
parameter sent from void QComboBox::editTextChanged(const QString &text) signal. -
thanks for correcting.
i am trying to echo the text entered by the user into QCombobox in the next line.
connect(echoComboBox, &QComboBox::currentTextChanged,this, &Window::onCurrentTextChanged);
auto text = echoComboBox->currentText(); passwordLineEdit = new QLineEdit; passwordLineEdit->setPlaceholderText("Password entered is : "); //But this line is displayed in a new window. and password is not echoed.
passwordLineEdit->show();
echoComboBox->show();
@curiosity said in QPointerEvent throws error:
auto text = echoComboBox->currentText();
passwordLineEdit = new QLineEdit;passwordLineEdit->setPlaceholderText("Password entered is : ");
Please think about this code and why it can't do what you want it to do and why you get a new window.
@JonB gave you all needed hints. -
@curiosity said in QPointerEvent throws error:
auto text = echoComboBox->currentText();
passwordLineEdit = new QLineEdit;passwordLineEdit->setPlaceholderText("Password entered is : ");
Please think about this code and why it can't do what you want it to do and why you get a new window.
@JonB gave you all needed hints.echoLayout->addWidget(passwordLabel, 2, 0);
echoLayout->addWidget(passwordLineEdit, 2, 1, 2, 3 );
this is added to the grid layoutQObject::connect(echoComboBox, &QComboBox::editTextChanged, this, [=](const QString &text) {
Window::onCurrentTextChanged(text);
});void onCurrentTextChanged(const QString &text) { passwordLineEdit->setPlaceholderText("Password entered is : "); passwordLineEdit->setText(text); //Is this the right way to set the text received from above signal. }
value entered is still not reflecting
-
echoLayout->addWidget(passwordLabel, 2, 0);
echoLayout->addWidget(passwordLineEdit, 2, 1, 2, 3 );
this is added to the grid layoutQObject::connect(echoComboBox, &QComboBox::editTextChanged, this, [=](const QString &text) {
Window::onCurrentTextChanged(text);
});void onCurrentTextChanged(const QString &text) { passwordLineEdit->setPlaceholderText("Password entered is : "); passwordLineEdit->setText(text); //Is this the right way to set the text received from above signal. }
value entered is still not reflecting
@curiosity said in QPointerEvent throws error:
QObject::connect(echoComboBox, &QComboBox::editTextChanged, this, [=](const QString &text) {
Window::onCurrentTextChanged(text);
});There is no need for a lambda, just connect onCurrentTextChanged directly to the signal.
-
echoLayout->addWidget(passwordLabel, 2, 0);
echoLayout->addWidget(passwordLineEdit, 2, 1, 2, 3 );
this is added to the grid layoutQObject::connect(echoComboBox, &QComboBox::editTextChanged, this, [=](const QString &text) {
Window::onCurrentTextChanged(text);
});void onCurrentTextChanged(const QString &text) { passwordLineEdit->setPlaceholderText("Password entered is : "); passwordLineEdit->setText(text); //Is this the right way to set the text received from above signal. }
value entered is still not reflecting
-
echoLayout->addWidget(passwordLabel, 2, 0);
echoLayout->addWidget(passwordLineEdit, 2, 1, 2, 3 );
this is added to the grid layoutQObject::connect(echoComboBox, &QComboBox::editTextChanged, this, [=](const QString &text) {
Window::onCurrentTextChanged(text);
});void onCurrentTextChanged(const QString &text) { passwordLineEdit->setPlaceholderText("Password entered is : "); passwordLineEdit->setText(text); //Is this the right way to set the text received from above signal. }
value entered is still not reflecting
@curiosity said in QPointerEvent throws error:
value entered is still not reflecting
Not sure where you are at now. Yes, calling
passwordLineEdit->setText(text);
should set the text from the string. Check what is in the string. Check you are getting the signal by putting aqDebug()
or something in the slot so that you know it is being called. -
@curiosity said in QPointerEvent throws error:
value entered is still not reflecting
Not sure where you are at now. Yes, calling
passwordLineEdit->setText(text);
should set the text from the string. Check what is in the string. Check you are getting the signal by putting aqDebug()
or something in the slot so that you know it is being called.@JonB
Ialready checked by planting a breakpoint in onCurrentTextChanged . on running and entering the text in the place holder i was expecting to hit the breakpoint, but it didnt hit.
this is my connect statementconnect(echoComboBox,&QComboBox::editTextChanged, this, &Window::onCurrentTextChanged);
void onCurrentTextChanged(const QString &text) { qDebug() << QString(" entered text is ")<< text;
//nothing is printed here in the application tab in qtcreator. it is not even hitting this breakpoint
passwordLineEdit->setPlaceholderText("Password entered is : ");
passwordLineEdit->setText(text);
passwordLineEdit->show();
passwordLineEdit->setEchoMode(QLineEdit::PasswordEchoOnEdit);}
-
@JonB
Ialready checked by planting a breakpoint in onCurrentTextChanged . on running and entering the text in the place holder i was expecting to hit the breakpoint, but it didnt hit.
this is my connect statementconnect(echoComboBox,&QComboBox::editTextChanged, this, &Window::onCurrentTextChanged);
void onCurrentTextChanged(const QString &text) { qDebug() << QString(" entered text is ")<< text;
//nothing is printed here in the application tab in qtcreator. it is not even hitting this breakpoint
passwordLineEdit->setPlaceholderText("Password entered is : ");
passwordLineEdit->setText(text);
passwordLineEdit->show();
passwordLineEdit->setEchoMode(QLineEdit::PasswordEchoOnEdit);}
@curiosity said in QPointerEvent throws error:
void onCurrentTextChanged(const QString &text)...
This is a free function... How does this even compile?
Please provide your full relevant code which actually compiles.
-
@curiosity said in QPointerEvent throws error:
void onCurrentTextChanged(const QString &text)...
This is a free function... How does this even compile?
Please provide your full relevant code which actually compiles.
@Christian-Ehrlicher
but i am using this as a slot. Please check the connect statement -
@Christian-Ehrlicher
but i am using this as a slot. Please check the connect statementvoid MainWindow::onCurrentTextChanged() and void onCurrentTextChanged() are two different functions. Provide your full code including the header.
-
void MainWindow::onCurrentTextChanged() and void onCurrentTextChanged() are two different functions. Provide your full code including the header.
-
And now please format your code with the code (</>) tags so it is readable for others.
Your header does not match the source - this does not compile. And then you have a local variable echoLabel but connect the member later on... -
And now please format your code with the code (</>) tags so it is readable for others.
Your header does not match the source - this does not compile. And then you have a local variable echoLabel but connect the member later on...@Christian-Ehrlicher
//NewWidget.cpp#include "NewWidget.h" #include <iostream> using namespace std; #include <QComboBox> #include <QGridLayout> #include <QGroupBox> #include <QLabel> #include <QLineEdit> #include <QtWidgets> Window::Window(QWidget *parent) QWidget(parent) { QGroupBox *echoGroup = new QGroupBox(tr("Echo"));
QLabel *echoLabel = new QLabel(tr("Mode:")); QComboBox *echoComboBox = new QComboBox; echoComboBox->addItem(tr("Normal")); echoComboBox->addItem(tr("Password")); echoComboBox->addItem(tr("PasswordEchoOnEdit")); echoComboBox->addItem(tr("No Echo")); echoLineEdit = new QLineEdit; echoLineEdit->setPlaceholderText("Placeholder Text"); QLabel *passwordLabel = new QLabel(tr("Password entered is :")); passwordLineEdit = new QLineEdit; QGroupBox *validatorGroup = new QGroupBox(tr("Validator")); QLabel *validatorLabel = new QLabel(tr("Type:")); QComboBox *validatorComboBox = new QComboBox; validatorComboBox->addItem(tr("No validator")); validatorComboBox->addItem(tr("Integer validator")); validatorComboBox->addItem(tr("Double validator")); validatorLineEdit = new QLineEdit; validatorLineEdit->setPlaceholderText("Placeholder Text"); QGroupBox *alignmentGroup = new QGroupBox(tr("Alignment")); QLabel *alignmentLabel = new QLabel(tr("Type:")); QComboBox *alignmentComboBox = new QComboBox; alignmentComboBox->addItem(tr("Left")); alignmentComboBox->addItem(tr("Centered")); alignmentComboBox->addItem(tr("Right")); alignmentLineEdit = new QLineEdit; alignmentLineEdit->setPlaceholderText("Placeholder Text");/>
connect(echoComboBox,&QComboBox::editTextChanged, this, &Window::onCurrentTextChanged);
connect(validatorComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated),this, &Window::validatorChanged); connect(alignmentComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &Window::alignmentChanged); QGridLayout *echoLayout = new QGridLayout; echoLayout->addWidget(echoLabel, 0, 0); echoLayout->addWidget(echoComboBox, 0, 1, Qt::AlignLeft); echoLayout->addWidget(echoLineEdit, 1, 0, 1, 2); echoLayout->addWidget(passwordLabel, 2, 0); echoLayout->addWidget(passwordLineEdit, 2, 2, 1, 2 ); echoLayout->setRowStretch(0, 5); echoGroup->setLayout(echoLayout); QGridLayout *validatorLayout = new QGridLayout; validatorLayout->addWidget(validatorLabel, 0, 0); validatorLayout->addWidget(validatorComboBox, 0, 1); validatorLayout->addWidget(validatorLineEdit, 1, 0, 1, 2); validatorGroup->setLayout(validatorLayout); QGridLayout *alignmentLayout = new QGridLayout; alignmentLayout->addWidget(alignmentLabel, 0, 0); alignmentLayout->addWidget(alignmentComboBox, 0, 1); alignmentLayout->addWidget(alignmentLineEdit, 1, 0, 1, 2); alignmentGroup-> setLayout(alignmentLayout); QGridLayout *grid = new QGridLayout; grid->addWidget(createFirstGroup(), 0, 1); grid->heightForWidth(10); grid->setRowStretch(0,50); //setWindowTitle(tr("Radio Buttons")); QGridLayout *layout = new QGridLayout; layout->addWidget(echoGroup, 0, 0); layout->addWidget(validatorGroup, 1, 0); layout->addWidget(alignmentGroup, 2, 0); layout->addWidget(createFirstGroup(), 0, 1); //layout->addWidget(accessGroup, 1, 1); setLayout(layout); setWindowTitle(tr("Line Edits"));
}
QGroupBox *Window::createFirstGroup() { QGroupBox *groupBox = new QGroupBox(tr("Radio Buttons group")); QRadioButton *radio1 = new QRadioButton(tr("&Radio button 1")); QRadioButton *radio2 = new QRadioButton(tr("R&adio button 2")); QRadioButton *radio3 = new QRadioButton(tr("Ra&dio button 3")); radio1->setChecked(true); QVBoxLayout *vbox = new QVBoxLayout; vbox->addWidget(radio1); vbox->addWidget(radio2); vbox->addWidget(radio3); vbox->addStretch(1); groupBox->setLayout(vbox); resize(100, 200); return groupBox; } void Window::echoChanged(int index) { switch (index) { case 0: echoLineEdit->setEchoMode(QLineEdit::Normal); break; case 1: echoLineEdit->setEchoMode(QLineEdit::Password); break; case 2: echoLineEdit->setEchoMode(QLineEdit::PasswordEchoOnEdit); break; case 3: echoLineEdit->setEchoMode(QLineEdit::NoEcho); break; } } void Window::validatorChanged(int index) { switch (index) { case 0: validatorLineEdit->setValidator(nullptr); break; case 1: validatorLineEdit->setValidator(new QIntValidator( validatorLineEdit)); break; case 2: validatorLineEdit->setValidator(new QDoubleValidator(-999.0, 999.0, 2, validatorLineEdit)); break; } validatorLineEdit->clear(); } void Window::alignmentChanged(int index) { switch (index) { case 0: alignmentLineEdit->setAlignment(Qt::AlignLeft); break; case 1: alignmentLineEdit->setAlignment(Qt::AlignCenter); break; case 2: alignmentLineEdit->setAlignment(Qt::AlignRight); break; } }
void Window::onCurrentTextChanged(const QString &text)
{
qDebug() << QString(" entered text is ")<< text;
passwordLineEdit->setPlaceholderText("Password entered is : ");
passwordLineEdit->setText(text);
passwordLineEdit->show();
passwordLineEdit->setEchoMode(QLineEdit::PasswordEchoOnEdit);
} -
@Christian-Ehrlicher
//NewWidget.cpp#include "NewWidget.h" #include <iostream> using namespace std; #include <QComboBox> #include <QGridLayout> #include <QGroupBox> #include <QLabel> #include <QLineEdit> #include <QtWidgets> Window::Window(QWidget *parent) QWidget(parent) { QGroupBox *echoGroup = new QGroupBox(tr("Echo"));
QLabel *echoLabel = new QLabel(tr("Mode:")); QComboBox *echoComboBox = new QComboBox; echoComboBox->addItem(tr("Normal")); echoComboBox->addItem(tr("Password")); echoComboBox->addItem(tr("PasswordEchoOnEdit")); echoComboBox->addItem(tr("No Echo")); echoLineEdit = new QLineEdit; echoLineEdit->setPlaceholderText("Placeholder Text"); QLabel *passwordLabel = new QLabel(tr("Password entered is :")); passwordLineEdit = new QLineEdit; QGroupBox *validatorGroup = new QGroupBox(tr("Validator")); QLabel *validatorLabel = new QLabel(tr("Type:")); QComboBox *validatorComboBox = new QComboBox; validatorComboBox->addItem(tr("No validator")); validatorComboBox->addItem(tr("Integer validator")); validatorComboBox->addItem(tr("Double validator")); validatorLineEdit = new QLineEdit; validatorLineEdit->setPlaceholderText("Placeholder Text"); QGroupBox *alignmentGroup = new QGroupBox(tr("Alignment")); QLabel *alignmentLabel = new QLabel(tr("Type:")); QComboBox *alignmentComboBox = new QComboBox; alignmentComboBox->addItem(tr("Left")); alignmentComboBox->addItem(tr("Centered")); alignmentComboBox->addItem(tr("Right")); alignmentLineEdit = new QLineEdit; alignmentLineEdit->setPlaceholderText("Placeholder Text");/>
connect(echoComboBox,&QComboBox::editTextChanged, this, &Window::onCurrentTextChanged);
connect(validatorComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated),this, &Window::validatorChanged); connect(alignmentComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &Window::alignmentChanged); QGridLayout *echoLayout = new QGridLayout; echoLayout->addWidget(echoLabel, 0, 0); echoLayout->addWidget(echoComboBox, 0, 1, Qt::AlignLeft); echoLayout->addWidget(echoLineEdit, 1, 0, 1, 2); echoLayout->addWidget(passwordLabel, 2, 0); echoLayout->addWidget(passwordLineEdit, 2, 2, 1, 2 ); echoLayout->setRowStretch(0, 5); echoGroup->setLayout(echoLayout); QGridLayout *validatorLayout = new QGridLayout; validatorLayout->addWidget(validatorLabel, 0, 0); validatorLayout->addWidget(validatorComboBox, 0, 1); validatorLayout->addWidget(validatorLineEdit, 1, 0, 1, 2); validatorGroup->setLayout(validatorLayout); QGridLayout *alignmentLayout = new QGridLayout; alignmentLayout->addWidget(alignmentLabel, 0, 0); alignmentLayout->addWidget(alignmentComboBox, 0, 1); alignmentLayout->addWidget(alignmentLineEdit, 1, 0, 1, 2); alignmentGroup-> setLayout(alignmentLayout); QGridLayout *grid = new QGridLayout; grid->addWidget(createFirstGroup(), 0, 1); grid->heightForWidth(10); grid->setRowStretch(0,50); //setWindowTitle(tr("Radio Buttons")); QGridLayout *layout = new QGridLayout; layout->addWidget(echoGroup, 0, 0); layout->addWidget(validatorGroup, 1, 0); layout->addWidget(alignmentGroup, 2, 0); layout->addWidget(createFirstGroup(), 0, 1); //layout->addWidget(accessGroup, 1, 1); setLayout(layout); setWindowTitle(tr("Line Edits"));
}
QGroupBox *Window::createFirstGroup() { QGroupBox *groupBox = new QGroupBox(tr("Radio Buttons group")); QRadioButton *radio1 = new QRadioButton(tr("&Radio button 1")); QRadioButton *radio2 = new QRadioButton(tr("R&adio button 2")); QRadioButton *radio3 = new QRadioButton(tr("Ra&dio button 3")); radio1->setChecked(true); QVBoxLayout *vbox = new QVBoxLayout; vbox->addWidget(radio1); vbox->addWidget(radio2); vbox->addWidget(radio3); vbox->addStretch(1); groupBox->setLayout(vbox); resize(100, 200); return groupBox; } void Window::echoChanged(int index) { switch (index) { case 0: echoLineEdit->setEchoMode(QLineEdit::Normal); break; case 1: echoLineEdit->setEchoMode(QLineEdit::Password); break; case 2: echoLineEdit->setEchoMode(QLineEdit::PasswordEchoOnEdit); break; case 3: echoLineEdit->setEchoMode(QLineEdit::NoEcho); break; } } void Window::validatorChanged(int index) { switch (index) { case 0: validatorLineEdit->setValidator(nullptr); break; case 1: validatorLineEdit->setValidator(new QIntValidator( validatorLineEdit)); break; case 2: validatorLineEdit->setValidator(new QDoubleValidator(-999.0, 999.0, 2, validatorLineEdit)); break; } validatorLineEdit->clear(); } void Window::alignmentChanged(int index) { switch (index) { case 0: alignmentLineEdit->setAlignment(Qt::AlignLeft); break; case 1: alignmentLineEdit->setAlignment(Qt::AlignCenter); break; case 2: alignmentLineEdit->setAlignment(Qt::AlignRight); break; } }
void Window::onCurrentTextChanged(const QString &text)
{
qDebug() << QString(" entered text is ")<< text;
passwordLineEdit->setPlaceholderText("Password entered is : ");
passwordLineEdit->setText(text);
passwordLineEdit->show();
passwordLineEdit->setEchoMode(QLineEdit::PasswordEchoOnEdit);
}I tried formatting it. but this was how it shoed up after posting NewWidget.cpp
#ifndef WINDOW_H #define WINDOW_H #include <QWidget> #include <QLineEdit> #include <QDebug> QT_BEGIN_NAMESPACE class QLineEdit; class QGroupBox; QT_END_NAMESPACE class Window : public QWidget { Q_OBJECT public: QLineEdit *passwordLineEdit; Window(QWidget *parent = nullptr); private: QLineEdit *echoLineEdit; QLineEdit *validatorLineEdit; QLineEdit *alignmentLineEdit; public slots: void echoChanged(int); void validatorChanged(int); void alignmentChanged(int); QGroupBox *createFirstGroup(); }; #endif
#include <QApplication> #include "NewWidget.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); Window window; window.show(); return app.exec(); }
code is compiling and running.. except that it is not echoing the text entered
-
I tried formatting it. but this was how it shoed up after posting NewWidget.cpp
#ifndef WINDOW_H #define WINDOW_H #include <QWidget> #include <QLineEdit> #include <QDebug> QT_BEGIN_NAMESPACE class QLineEdit; class QGroupBox; QT_END_NAMESPACE class Window : public QWidget { Q_OBJECT public: QLineEdit *passwordLineEdit; Window(QWidget *parent = nullptr); private: QLineEdit *echoLineEdit; QLineEdit *validatorLineEdit; QLineEdit *alignmentLineEdit; public slots: void echoChanged(int); void validatorChanged(int); void alignmentChanged(int); QGroupBox *createFirstGroup(); }; #endif
#include <QApplication> #include "NewWidget.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); Window window; window.show(); return app.exec(); }
code is compiling and running.. except that it is not echoing the text entered
Please read my post carefully and fix the errors in your code.