Try this. It worked for me if I understand you correctly.
- In Qt designer, go to signals/slots editor.
- Right-click cmd_1.
- Choose "Go to slot..."
- Choose "clicked()". This will create a slot for you.
- In the slot, update your LineEdit txt widget. ui->txt->setText("1");
- Do the same for the other buttons.
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QMainWindow>
namespace Ui
{
class MainWindow;
}
{
Q_OBJECT
public:
~MainWindow();
private:
Ui::MainWindow *ui;
private slots:
void on_cmd_3_clicked();
void on_cmd_2_clicked();
void on_cmd_1_clicked();
void on_pushButton_clicked();
};
#endif // MAINWINDOW_H
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
){
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
qDebug("button was pushed");
}
void MainWindow::on_cmd_1_clicked()
{
ui->txt->setText("1");
}
void MainWindow::on_cmd_2_clicked()
{
ui->txt->setText("2");
}
void MainWindow::on_cmd_3_clicked()
{
ui->txt->setText("3");
}
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QMainWindow>
namespace Ui
{
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
private slots:
void on_cmd_3_clicked();
void on_cmd_2_clicked();
void on_cmd_1_clicked();
void on_pushButton_clicked();
};
#endif // MAINWINDOW_H
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
qDebug("button was pushed");
}
void MainWindow::on_cmd_1_clicked()
{
ui->txt->setText("1");
}
void MainWindow::on_cmd_2_clicked()
{
ui->txt->setText("2");
}
void MainWindow::on_cmd_3_clicked()
{
ui->txt->setText("3");
}
To copy to clipboard, switch view to plain text mode
Bookmarks