QPushButton *pushButton = new QPushButton("Button");QTextEdit *textEdit = new QTextEdit();QString str = "TEST";connect(pushButton, SIGNAL(clicked()), textEdit, SLOT(setPlainText(str)));
// WRONG QObject::connect(scrollBar, SIGNAL(valueChanged(int value)), label, SLOT(setNum(int value)));
connect(pushButton, SIGNAL(clicked(QString)), textEdit, SLOT(setPlainText(QString)));
C++ (Qt)// main.cpp#include <QApplication>#include "MyDialog.h"int main(int argc, char *argv[]){QApplication a(argc, argv);MyDialog b;b.show();return a.exec();}
C++ (Qt)// MyDialog.h#ifndef MYDIALOG_H#define MYDIALOG_H#include <QDialog>class QString;class QTextEdit;class QPushButton;class MyDialog : public QDialog{Q_OBJECTpublic:MyDialog();private:QPushButton *pushButton;QTextEdit *textEdit;QString str;private slots:void slot();};#endif // MYDIALOG_H
C++ (Qt)// MyDialog.cpp#include "MyDialog.h"#include <QtGui>MyDialog::MyDialog(){ pushButton = new QPushButton("Button"); textEdit = new QTextEdit(); str = "TEST"; QHBoxLayout *Layout = new QHBoxLayout(this); Layout->addWidget(textEdit); Layout->addWidget(pushButton); setLayout(Layout); connect(pushButton, SIGNAL(clicked()), SLOT(slot()));;} void MyDialog::slot(){ textEdit->setPlainText(str);}