Qt GUI merge C++ console app
-
Hi,
In order to learn about Qt, I made a small GUI by Qt Designer 5.0.2 (via MSVC and Qt-VS-add-in). The GUI contains 3 lineEdits (2 for entry 1 for display result) and 1 pushButton to start the compute.
Code are as follows:
h.file @
#ifndef TEST41_QT6_H
#define TEST41_QT6_H#include <QtWidgets/QMainWindow>
#include "ui_test41_qt6.h"class test41_qt6 : public QMainWindow
{
Q_OBJECTpublic:
test41_qt6(QWidget *parent = 0);
~test41_qt6();private:
Ui::test41_qt6Class ui;public slots: void numberChanged();
};#endif // TEST41_QT6_H
@cpp file @
#include "test41_qt6.h"test41_qt6::test41_qt6(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(numberChanged()));
}test41_qt6::~test41_qt6()
{}
void test41_qt6::numberChanged()
{
double nOne = ui.lineEdit->text().toDouble();
double nTwo = ui.lineEdit_2->text().toDouble();
double nAdd = nOne + nTwo;
ui.lineEdit_3->setText(QString::number(nAdd));
}
@main.cpp file @
#include "test41_qt6.h"
#include <QtWidgets/QApplication>
#include <array>using namespace std;
int main(int argc, char *argv[])
{
array<double,5> x = {1.0, 2.0, 3.0, 4.0, 5.0};QApplication a(argc, argv);
test41_qt6 w;
w.show();
return a.exec();
}
@In main.cpp I build an array. I want to send the value of nOne and nTwo (entered from GUI) to main.cpp and add them to x[0] (1st ele of x), then return the result to GUI and display it in lineEdit_3.
Could anyone please tell me how to do this? Thanks in advance!
-
I suggest to start with some examples as they are shipped with Qt libs eg. the "dialog examples":http://qt-project.org/doc/qt-5.0/qtwidgets/dialogs-standarddialogs.html
This way you are probably much faster in understanding the way to handle the gui together with your application. -
Thanks. Anyone can give more detailed help, please?
-
Hi,
As koahnig suggested, read the Qt examples and documentation. They are well written and explained and the dialog example shows how to do what you want to achieve.
To get you started: don't pass the value back and forth through your main function.
-
Can anyone help me in concrete way, please? Is what I want to do too complicated or because nobody knows how to do it?