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. Calling C++ function on QT GUI
QtWS25 Last Chance

Calling C++ function on QT GUI

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 7 Posters 1.2k Views
  • 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.
  • A Offline
    A Offline
    ankush
    wrote on 8 Jan 2023, 09:16 last edited by
    #1

    Please help me, i want to call simple c++ function (independent from QT) on QT GUI, is there any way it can be done?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 8 Jan 2023, 09:36 last edited by
      #2

      Hi,

      Qt is a C++ framework so there's nothing special here. Use your library as usual.

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

      A 1 Reply Last reply 8 Jan 2023, 10:03
      2
      • S SGaist
        8 Jan 2023, 09:36

        Hi,

        Qt is a C++ framework so there's nothing special here. Use your library as usual.

        A Offline
        A Offline
        ankush
        wrote on 8 Jan 2023, 10:03 last edited by
        #3

        @SGaist ,
        Hi, I want to call simple c++ class function on GUI how can i do it?

        C A 2 Replies Last reply 8 Jan 2023, 10:13
        0
        • A ankush
          8 Jan 2023, 10:03

          @SGaist ,
          Hi, I want to call simple c++ class function on GUI how can i do it?

          C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 8 Jan 2023, 10:13 last edited by
          #4

          @ankush said in Calling C++ function on QT GUI:

          Hi, I want to call simple c++ class function on GUI how can i do it?

          As you would do it in a normal c++ application - there is nothing special when you use Qt functions.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          A 1 Reply Last reply 8 Jan 2023, 10:25
          1
          • A ankush
            8 Jan 2023, 10:03

            @SGaist ,
            Hi, I want to call simple c++ class function on GUI how can i do it?

            A Offline
            A Offline
            ankush
            wrote on 8 Jan 2023, 10:15 last edited by
            #5

            @ankush said in Calling C++ function on QT GUI:

            on

            my c++ class function is independent from qt, now i want to call that function on qt and show output on GUI not on terminal. if possible can explain me with code.

            1 Reply Last reply
            0
            • C Christian Ehrlicher
              8 Jan 2023, 10:13

              @ankush said in Calling C++ function on QT GUI:

              Hi, I want to call simple c++ class function on GUI how can i do it?

              As you would do it in a normal c++ application - there is nothing special when you use Qt functions.

              A Offline
              A Offline
              ankush
              wrote on 8 Jan 2023, 10:25 last edited by
              #6

              @Christian-Ehrlicher, @SGaist
              my c++ class function is independent from qt, now i want to call that function on qt and show output on GUI not on terminal. if possible can explain me with code.

              //

              i have c++ class that is independent from qt, and inside this class i have one function that print any string (for example: cout<<"Hello world" on termincal), but now i want to call this function on QT gui and show output on GUI.

              C 1 Reply Last reply 8 Jan 2023, 10:26
              0
              • A ankush
                8 Jan 2023, 10:25

                @Christian-Ehrlicher, @SGaist
                my c++ class function is independent from qt, now i want to call that function on qt and show output on GUI not on terminal. if possible can explain me with code.

                //

                i have c++ class that is independent from qt, and inside this class i have one function that print any string (for example: cout<<"Hello world" on termincal), but now i want to call this function on QT gui and show output on GUI.

                C Offline
                C Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 8 Jan 2023, 10:26 last edited by
                #7

                @ankush said in Calling C++ function on QT GUI:

                inside this class i have one function that print any string (for example: cout<<"Hello world" on termincal), but now i want to call this function on QT gui and show output on GUI.

                Adjust your class so that it does not output it to cout but return it e.g. as return value or in a separate function. Then call this function and show the string in your gui.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                A 1 Reply Last reply 8 Jan 2023, 10:55
                2
                • C Christian Ehrlicher
                  8 Jan 2023, 10:26

                  @ankush said in Calling C++ function on QT GUI:

                  inside this class i have one function that print any string (for example: cout<<"Hello world" on termincal), but now i want to call this function on QT gui and show output on GUI.

                  Adjust your class so that it does not output it to cout but return it e.g. as return value or in a separate function. Then call this function and show the string in your gui.

                  A Offline
                  A Offline
                  ankush
                  wrote on 8 Jan 2023, 10:55 last edited by
                  #8

                  @Christian-Ehrlicher,
                  can you please show me with code how its done, it will be great help

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    ankush
                    wrote on 8 Jan 2023, 11:52 last edited by
                    #9

                    @Christian-Ehrlicher , @SGaist
                    Is it possible to have existing C++ code work with Qt? i want combine my qt gui with C++ back end.

                    1 Reply Last reply
                    0
                    • Axel SpoerlA Offline
                      Axel SpoerlA Offline
                      Axel Spoerl
                      Moderators
                      wrote on 8 Jan 2023, 12:13 last edited by
                      #10

                      @ankush said in Calling C++ function on QT GUI:

                      Is it possible to have existing C++ code work with Qt? i want combine my qt gui with C++ back end.

                      Of course that's possible, even in many ways.
                      Just to clarify: At the beginning, a "simple C++ function" is mentioned to be called.
                      => Such a function can easily be added to the UI code in Qt and called from there (e.g. encapsulated in a class, maybe a singleton).

                      At the end, a "C++ backend" is mentioned, which suggests much more complexity than a simple function.
                      => It could be compiled as a separate library, the header(s) of which are included from the Qt project and the project linked against it.

                      There are more options e.g. making a command-line call, implementing a REST API, ... but that depends on the use case.
                      There is no one-size-fits-all that applies to any use case and any complexity.

                      Software Engineer
                      The Qt Company, Oslo

                      A 1 Reply Last reply 9 Jan 2023, 08:28
                      1
                      • Axel SpoerlA Axel Spoerl
                        8 Jan 2023, 12:13

                        @ankush said in Calling C++ function on QT GUI:

                        Is it possible to have existing C++ code work with Qt? i want combine my qt gui with C++ back end.

                        Of course that's possible, even in many ways.
                        Just to clarify: At the beginning, a "simple C++ function" is mentioned to be called.
                        => Such a function can easily be added to the UI code in Qt and called from there (e.g. encapsulated in a class, maybe a singleton).

                        At the end, a "C++ backend" is mentioned, which suggests much more complexity than a simple function.
                        => It could be compiled as a separate library, the header(s) of which are included from the Qt project and the project linked against it.

                        There are more options e.g. making a command-line call, implementing a REST API, ... but that depends on the use case.
                        There is no one-size-fits-all that applies to any use case and any complexity.

                        A Offline
                        A Offline
                        ankush
                        wrote on 9 Jan 2023, 08:28 last edited by
                        #11

                        Thank you @Axel-Spoerl, @Christian-Ehrlicher , @SGaist for your valuable time, i really appreciate that. I will be following you guys instruction and if some small sample project available that is combination of standard c++ and QT gui please tell me.
                        Thank you again.

                        W 1 Reply Last reply 10 Jan 2023, 19:14
                        0
                        • S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 9 Jan 2023, 20:28 last edited by
                          #12

                          You are really over complicating things. Most Qt applications out there are using external C++ libraries. Just look at any of the KDE applications.

                          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
                          1
                          • A ankush
                            9 Jan 2023, 08:28

                            Thank you @Axel-Spoerl, @Christian-Ehrlicher , @SGaist for your valuable time, i really appreciate that. I will be following you guys instruction and if some small sample project available that is combination of standard c++ and QT gui please tell me.
                            Thank you again.

                            W Offline
                            W Offline
                            wrosecrans
                            wrote on 10 Jan 2023, 19:14 last edited by
                            #13

                            @ankush said in Calling C++ function on QT GUI:

                            some small sample project available that is combination of standard c++ and QT gui please tell me.

                            Literally every one of the Qt examples. Qt applications are written in C++.

                            1 Reply Last reply
                            1
                            • S Offline
                              S Offline
                              Smedskjaer
                              wrote on 9 Feb 2023, 12:47 last edited by
                              #14

                              Hi,

                              I personally would appreciate an example in code too. I am new to QT and GUI's in general, and an example here can help me.

                              If I were to write classes, with files a.h, b.h and c.h, and a.cpp, b.cpp and c.cpp, and main.cpp, where class d inherits class a, b and c, how can I code a GUI which passes a user input from a text box to a function of class d, and display an output in the GUI?

                              Please bear with me. I know I am asking a seemingly basic question, but an explanation and code example here will be most helpful to me.

                              JonBJ 1 Reply Last reply 9 Feb 2023, 13:15
                              0
                              • S Smedskjaer
                                9 Feb 2023, 12:47

                                Hi,

                                I personally would appreciate an example in code too. I am new to QT and GUI's in general, and an example here can help me.

                                If I were to write classes, with files a.h, b.h and c.h, and a.cpp, b.cpp and c.cpp, and main.cpp, where class d inherits class a, b and c, how can I code a GUI which passes a user input from a text box to a function of class d, and display an output in the GUI?

                                Please bear with me. I know I am asking a seemingly basic question, but an explanation and code example here will be most helpful to me.

                                JonBJ Offline
                                JonBJ Offline
                                JonB
                                wrote on 9 Feb 2023, 13:15 last edited by JonB 2 Sept 2023, 13:24
                                #15

                                @Smedskjaer
                                Hello and welcome.

                                Please understand it takes us time too if we type in everything about Qt which is available in examples online/in the Help!

                                Before you go any further. What do classes A, B & C do, what are they there for? "where class d inherits class a, b and c": although possible, my strong suspicion is that you will not want a class D which inherits from 3 other classes!

                                I would start out writing your first basic Qt program with just one widget/main window, perhaps designed in the Designer. Then I would add just one extra class A. Do things a bit at a time and ask then.

                                how can I code a GUI which passes a user input from a text box to a function of class d, and display an output in the GUI?

                                The basic answer might be

                                // in GUI, like a widget or main window
                                D d;
                                QString text = ui->textbox->text();
                                QString newtext = d.someMethod(text);
                                ui->label->setText(newtext);
                                

                                but it all depends on what D is/does, what you really want, etc. etc.

                                1 Reply Last reply
                                1

                                • Login

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