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
Forum Updated to NodeBB v4.3 + New Features

Calling C++ function on QT GUI

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 7 Posters 2.1k Views 3 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.
  • Christian EhrlicherC Christian Ehrlicher

    @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 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.

    Christian EhrlicherC 1 Reply Last reply
    0
    • A ankush

      @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.

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 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
      2
      • Christian EhrlicherC Christian Ehrlicher

        @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 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 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 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
            1
            • Axel SpoerlA Axel Spoerl

              @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 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
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on 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

                  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 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 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
                    0
                    • S Smedskjaer

                      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 last edited by JonB
                      #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