Solved using UI with signals and elements
-
hi I've been studying qt recently and i know how to use signals in fact the problem I am facing right now I've already wrote it in cpp,
#include <QApplication> #include <QLineEdit> #include <QWidget> #include <QLabel> #include <QVBoxLayout> int main(int argc, char *argv[]) { QApplication a(argc, argv); QWidget widget; QLineEdit *lineEdit = new QLineEdit; QLabel *label = new QLabel; QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(lineEdit); layout->addWidget(label); widget.setLayout(layout); QObject::connect( lineEdit, SIGNAL(textChanged(const QString&)), label, SLOT(setText(const QString&)) ); widget.show(); return a.exec(); }
so I'm trying to write the same program using ui so I create the same ui and right click on line edit go to slots and choose ontextchanged and it gives me this:
#include "mainwindow.hpp" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_lineEdit_textChanged(const QString &arg1) { }
i don't know what to do next. how do i connect a ui element 's signal to another slot? what should i write in this case inside the
void MainWindow::on_lineEdit_textChanged(const QString &arg1) { }
method?
-
@nullbuil7 said in using UI with signals and elements:
what should i write in this case inside the
ui->label->setText(arg1);
I guess? Or what is the question?
-
I found the answer here:
https://doc.qt.io/archives/qt-4.8/designer-connection-mode.html
It's from Qt 4.8 but still unchanged.