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. how to pass a double value from c++ to a qt user interface
Forum Updated to NodeBB v4.3 + New Features

how to pass a double value from c++ to a qt user interface

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 577 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.
  • B Offline
    B Offline
    brian777754
    wrote on 13 Jun 2019, 18:54 last edited by
    #1

    I have made a user interface using qt creator 5.9.1. I want to be able to connect it now to an external c++ program so that I can update the values of the double spinboxes. Could someone show a simple example of what code I would need to write to send the double value from the external c++ program. And what code I would need to write to receive that value in the qt program.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      brian777754
      wrote on 13 Jun 2019, 19:34 last edited by
      #2

      I mean a c++ program that is not on qt. I am using ubunto 16.04

      1 Reply Last reply
      0
      • V Offline
        V Offline
        VRonin
        wrote on 13 Jun 2019, 19:55 last edited by
        #3

        https://doc.qt.io/qt-5/qprocess.html#communicating-via-channels

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        B 1 Reply Last reply 13 Jun 2019, 20:02
        2
        • V VRonin
          13 Jun 2019, 19:55

          https://doc.qt.io/qt-5/qprocess.html#communicating-via-channels

          B Offline
          B Offline
          brian777754
          wrote on 13 Jun 2019, 20:02 last edited by
          #4

          @VRonin could you give me a simple example of how to actually implement this to pass a double value in from c++ to qt I have read this but I am still confused by it.

          1 Reply Last reply
          0
          • V Offline
            V Offline
            VRonin
            wrote on 13 Jun 2019, 20:19 last edited by VRonin
            #5

            Should be something like:

            OtherProgram

            #include <iostream>
            int main(){
            double aNumber;
            std::cin >> aNumber;
            std::cout << "Doubled number: " << 2.0*aNumber;
            return 0;
            }
            

            QtProgram

            #include <QCoreApplication> 
            #include <QProcess>
            #include <QByteArray>
            #include <QDebug>
            int main(int argc, char **argv)
            {
            const double magicNumber = 1.56;
            QCoreApplication app(argc,argv);
            QProcess otherProcess;
            otherProcess.start("OtherProgram.exe");
            if (!otherProcess.waitForStarted())
                    return 1;
            otherProcess.write(QByteArray::number(magicNumber,'f'));
            if (!otherProcess.waitForReadyRead())
                    return 1;
            qDebug() << otherProcess.readAllStandardOutput();
            if (!otherProcess.waitForFinished())
                    return 1;
            return 0;
            }
            

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            B 1 Reply Last reply 13 Jun 2019, 20:23
            4
            • V VRonin
              13 Jun 2019, 20:19

              Should be something like:

              OtherProgram

              #include <iostream>
              int main(){
              double aNumber;
              std::cin >> aNumber;
              std::cout << "Doubled number: " << 2.0*aNumber;
              return 0;
              }
              

              QtProgram

              #include <QCoreApplication> 
              #include <QProcess>
              #include <QByteArray>
              #include <QDebug>
              int main(int argc, char **argv)
              {
              const double magicNumber = 1.56;
              QCoreApplication app(argc,argv);
              QProcess otherProcess;
              otherProcess.start("OtherProgram.exe");
              if (!otherProcess.waitForStarted())
                      return 1;
              otherProcess.write(QByteArray::number(magicNumber,'f'));
              if (!otherProcess.waitForReadyRead())
                      return 1;
              qDebug() << otherProcess.readAllStandardOutput();
              if (!otherProcess.waitForFinished())
                      return 1;
              return 0;
              }
              
              B Offline
              B Offline
              brian777754
              wrote on 13 Jun 2019, 20:23 last edited by
              #6

              @VRonin thank you so much

              1 Reply Last reply
              0

              1/6

              13 Jun 2019, 18:54

              • Login

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