我是一个 QT 初学者,我正在编写一个具有两个 QPushButtons 和两个 QTextEdits 的 GUI 应用程序。单击按钮 1 时,我只希望 QTextEdit 1 显示某些内容,单击按钮 2 时,我只希望 QTextEdit 2 显示某些内容,下面是我的代码,但它不起作用,因为我似乎无法将参数传递给槽法……
class EventProcessor: public QObject {
Q_OBJECT
public slots:
void PopulateEditTest(QTextEdit *textEdit, QString text)
{
textEdit->setText(text);
}
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget *window = new QWidget;
QTextEdit *result1 = new QTextEdit();
QTextEdit *result2 = new QTextEdit();
QPushButton *btFacility1 = new QPushButton("Facility 1");
QPushButton *btFacility2 = new QPushButton("Facility 2");
EventProcessor eventprocessor;
QObject::connect(btFacility1, SIGNAL(clicked()), &eventprocessor, SLOT(PopulateEditTest
(result1, "textEdit1")));
QObject::connect(btFacility2, SIGNAL(clicked()), result, SLOT(PopulateEditTest
(result2, "textEdit2")));
..........
return app.exec();
}
我想知道是否有类似的方法可以让这个工作?谢谢您的回答。