Calling C++ function on QT GUI
-
Hi,
Qt is a C++ framework so there's nothing special here. Use your library as usual.
-
@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.
-
@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.
@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-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.
@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.
-
@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.
@Christian-Ehrlicher,
can you please show me with code how its done, it will be great help -
@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. -
@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.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. -
You are really over complicating things. Most Qt applications out there are using external C++ libraries. Just look at any of the KDE applications.
-
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.@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++.
-
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.
-
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.
@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.