Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt GUI merge C++ console app
Forum Updated to NodeBB v4.3 + New Features

Qt GUI merge C++ console app

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dekeenfrance
    wrote on last edited by
    #1

    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_OBJECT

    public:
    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!

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      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.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dekeenfrance
        wrote on last edited by
        #3

        Thanks. Anyone can give more detailed help, please?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dekeenfrance
            wrote on last edited by
            #5

            Can anyone help me in concrete way, please? Is what I want to do too complicated or because nobody knows how to do it?

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved