C++ (Qt)// main.cpp#include "widget.h"#include <QApplication> int main(int argc, char *argv[]){ QApplication a(argc, argv); Widget w; w.show(); w.LineEdit("Текст"); return a.exec();}
C++ (Qt)// widget.h#ifndef WIDGET_H#define WIDGET_H #include <QWidget>#include <QString> namespace Ui { class Widget; } class Widget : public QWidget{ Q_OBJECT public: Ui::Widget *ui; explicit Widget(QWidget *parent = 0); ~Widget(); void LineEdit(QString);}; #endif // WIDGET_H
C++ (Qt)// widget.cpp#include "widget.h"#include "ui_widget.h" Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget){ ui->setupUi(this);} Widget::~Widget(){ delete ui;} void Widget::LineEdit(QString text){ ui->lineEdit->setText(text);}
C++ (Qt)connect(ui->pushButton, SIGNAL(clicked()), ui->lineEdit, SLOT(LineEdit));
C++ (Qt)connect(ui->pushButton, SIGNAL(clicked()), ui->lineEdit, SLOT(ui->lineEdit->setText("7890")));
C++ (Qt) connect(ui->pushButton, SIGNAL(clicked()), ui->lineEdit, SLOT(setText("Текст"))); // не работает connect(ui->pushButton_2, SIGNAL(clicked()), ui->lineEdit, SLOT(clear())); // работает
C++ (Qt)connect(ui->pushButton, SIGNAL(clicked()), ui->lineEdit, SLOT(setText(QString)));
C++ (Qt)#include "widget.h"#include "ui_widget.h" Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget){ ui->setupUi(this); connect(ui->pushButton, SIGNAL(clicked()), ui->lineEdit, SLOT(button_click())); connect(ui->pushButton_2, SIGNAL(clicked()), ui->lineEdit, SLOT(clear()));} void Widget::button_click(){ ui->lineEdit->setText("ТЕКСТ");}