Results 1 to 18 of 18

Thread: Qt with C?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt with C?

    Apologies, I didn't provide enough context.

    The primary application is written in C. I'd like to extend the application by adding a graphical window (with Qt) to simulate a VGA/Keboard/Mouse console, but leaving the core C program intact.

    I would need to abe able to create a Qt window from my C code, and display the graphics to it from the C code, and have it deliver events (keyboard, mouse) back to the C code.

    Is this scenario realistically possible with Qt?

  2. #2
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Qt with C?

    You can create first Qt project with needed Qt interface and then step by step adding functioonality ftom C code. I'm sure that this way hasn't perfect quality, but after some correctings it must working...

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qt with C?

    Is this scenario realistically possible with Qt?
    Yes it is, all thoug I didn't do it my self.
    As I said before, you have C bindings to Qt, check it out.

  4. #4
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt with C?

    Quote Originally Posted by DecWiz
    Apologies, I didn't provide enough context.

    The primary application is written in C. I'd like to extend the application by adding a graphical window (with Qt) to simulate a VGA/Keboard/Mouse console, but leaving the core C program intact.

    I would need to abe able to create a Qt window from my C code, and display the graphics to it from the C code, and have it deliver events (keyboard, mouse) back to the C code.

    Is this scenario realistically possible with Qt?
    The core will stay intact as long as you wish it and types conversions are clear enough for a C++ compiler (which is more strict than a C one in that domain).
    However, your project will not stay a C one, using a binding for C would be silly since any C code can be compiled by a C++ compiler!
    You'll just need to had GUI code and change the parameters of your compiler/IDE to make it compile your project in C++.
    Current Qt projects : QCodeEdit, RotiDeCode

  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qt with C?

    However, your project will not stay a C one, using a binding for C would be silly since any C code can be compiled by a C++ compiler!
    I am not sure what do you mean by that, but this is not quite true.
    Following your logic, the whole idea of language bindings would not make sense.
    This would mean a pyton project would have to be turned to a C++ project to use the PyQt.(python bindings for Qt).
    Qt binding are there for projects in the respective languages to interface to Qt, which means, the project stays in its original language.

    Correct me if I am wrong.

  6. #6
    Join Date
    Jan 2006
    Location
    Bern || Lausanne
    Posts
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt with C?

    That's not what he said.

    He said a C program also is a C++ program thus you can directly use a C++ Compiler and also directly use Qt without C bindings. That is, without changing the program or "really" converting it to C++.
    This is true for some C programs - but not for all of them. You probably will get tons of Warnings and maybe even some errors when compiling a C program with C++ (provided you have never done this before with the code and fixed the bugs)
    To come back to your analogy: If a python program could be compiled with any C++ compiler it would be silly to use the pyqt bindings...

    Peschmä
    No sig yet - just filling the space...

  7. #7
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qt with C?

    He said a C program also is a C++ program thus you can directly use a C++ Compiler and also directly use Qt without C bindings.
    This is not true.
    C++ has tottaly diferent name mangling then C, because of the features it has such as overloading and classes.
    So function signatures are not compatible between C and C++.
    This is also why you need to use the extern "C" directive when you want to include C code in C++ project.
    Its true, that some times you can get away with it, by just adding the C code and nothing more, but that is very much chance dependant, if it will work or not.

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
  •  
Qt is a trademark of The Qt Company.