PDA

View Full Version : how to use C code in qt?



shakthi
24th July 2011, 06:04
see i have one c code , printf("hello world"); normally this c program will run by gcc in console. i lyk to develop gui for this code. that is hello world should be display in dialog box of qt.. for that what i want to do?? how to add C code(linux c) in qt? what are the libraries should add? how to use the c code in qt like how to create object and how to synchronize? please help me soon

thanks in advance,
shakthi

Santosh Reddy
24th July 2011, 06:15
see i have one c code , printf("hello world"); normally this c program will run by gcc in console. i lyk to develop gui for this code. that is hello world should be display in dialog box of qt.. for that what i want to do??


#include <QtGui/QApplication>
#include <QLabel>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QLabel label("Hellow World");
label.show();

return a.exec();
}


how to add C code(linux c) in qt?
Qt works on C++, as C++ has in-built support for C, just compile you C code as you would do in plain C++, nothing more is required.


what are the libraries should add?
Just include required C++ headers, no Qt files are required.


how to use the c code in qt like how to create object and how to synchronize?
What do you mean by object, C does not have objects's concept, also what do you mean by synchronize?

vcernobai
24th July 2011, 10:16
Start by reading some Qt tutorials first!

shakthi
24th July 2011, 14:11
i think u ppl doesn't understand my thread.. see am gonna design gui for my c output.. that is back end c code and front end qt code.. for that what i want to do??


//What do you mean by object, C does not have objects's concept, also what do you mean by synchronize?


that i know, i mean for that whole c code how to create a variable to access??? synchronize in the sense, that printf hello world should display in dialog box .. dont give simple example like use label like tat.. am asking synchronization of two different language... see if ve use pthread.h, time.h header file, how to add those code in qt.. ???

//Start by reading some Qt tutorials first!


i ve read enough.. but i like to know language interconnection in qt. there is no tutorials i ve found so far. tats y asked here..

squidge
24th July 2011, 17:13
synchronize in the sense, that printf hello world should display in dialog box

You would execute the C code using QProcess, capture the output and use C++ application to shown output from C process into dialog box.

To do it in the same application you would have to write your own printf, but its not recommended to override such standard functions.

If you just want to combine C code with C++, then just include the C code as normal.

SixDegrees
24th July 2011, 17:46
Or, if you're trying to call a C function from within C++, then you simply have to remember that C is already C++; you call it just like any other function, you compile it just like any other function, and you link it just like any other pre-compiled object file or library.