Just a simple program to add text to textedit when button is clicked…
anything wrong here??
#include<QPushButton>
#include<QApplication>
#include<QTextEdit>
#include<QWidget>
#include<QHBoxLayout>
#include<QLabel>
int main(int argc,char *argv[])
{
QApplication app(argc,argv);
QHBoxLayout *layout=new QHBoxLayout;
QTextEdit *text = new QTextEdit();
QWidget window;
QPushButton *button;
layout->addWidget(text);
button = new QPushButton();
button->setText(QChar(i+48));
QObject::connect(button,SIGNAL(clicked()),text,SLOT(setPlainText("hai")));
layout->addWidget(button);
window.setLayout(layout);
window.resize(500, 500);
window.show();
return app.exec();
}
You can’t use
connectlike that. You cannot pass parameters to theSLOTthat are not present in the connectedSIGNAL.You will need to connect the
clicked()signal to your own slot (with no argument), and call thesetPlainTextfunction yourself (or emit a new signal that has aQStringparameter).The other option is to use a
QSignalMapper, as described in the Signals and Slots advanced usage section.