Results 1 to 6 of 6

Thread: how to use C code in qt?

  1. #1
    Join Date
    Jul 2011
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy how to use C code in qt?

    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

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: how to use C code in qt?

    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??
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include <QLabel>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7.  
    8. QLabel label("Hellow World");
    9. label.show();
    10.  
    11. return a.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    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?

  3. #3
    Join Date
    Dec 2009
    Location
    Romania, Iasi
    Posts
    18
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to use C code in qt?

    Start by reading some Qt tutorials first!

  4. #4
    Join Date
    Jul 2011
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to use C code in qt?

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

  5. #5
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to use C code in qt?

    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.

  6. #6
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: how to use C code in qt?

    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.

Similar Threads

  1. need help in qt code
    By doforumda in forum Qt Programming
    Replies: 5
    Last Post: 27th August 2010, 13:27
  2. int to hex code
    By nowire75 in forum Newbie
    Replies: 5
    Last Post: 14th January 2008, 17:00
  3. Qt 4.2.3 with C code
    By 3nc31 in forum Qt Programming
    Replies: 4
    Last Post: 19th October 2007, 22:05
  4. Pasting code from code tag in emacs
    By Gopala Krishna in forum General Discussion
    Replies: 0
    Last Post: 16th February 2007, 05:47
  5. Need help with C++ code!
    By therealjag in forum Qt Programming
    Replies: 4
    Last Post: 20th March 2006, 21:37

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.