Thread: QT and C

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    3

    QT and C

    Hello. Is it possible to create a GUI in QT with C? Or is it C++ only? Thanks.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I'm 95% sure it's C++ only.

    Of course, it is theoretically possible to make a shim-layer for C to C++ translation, but it's more complicated than the other way around, and it's probably not meaningful in this case.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    The Qt library is so enormous that any shim is either going to be very application-specific, or take years to write. Or you might spend a year writing the tool which would automatically create the shim. I've seen tons of adapter layers to allow accessing C++ libraries from C, but not something as huge as Qt.

    If you're using C, I'd stick with something like GTK.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  4. #4
    Registered User
    Join Date
    Mar 2009
    Posts
    3
    Thanks for the information. I've not really looked up on how to make C GUI's, are there are tools out there to make simple GUI's, like QT? It wouldn't have to be cross platform, as long as it could create GUI's on Windows thats fine, but it would be great if it was cross platform, or at least Windows and Linux anyway.

    Cheers.

  5. #5
    Registered User
    Join Date
    Feb 2008
    Posts
    19
    other than GTK there's IUP which looks nice and can be used in Lua too but there's no real tutorial about it, just the reference. GTK's got books on it instead and lots of tuts. It doesn't look very good in Windows tho, it's mainly for Linux.

  6. #6
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Gtk also has a programming and user forum. There seem to be a decent percentage of windows people there. It is also used on macs.

    I have never seen it on microsoft but I just googled "gtk+ microsoft screenshots" and there is stuff to look at, if you want to judge for yourself. It probably won't "blend in" unless you make it.

    Linux GUI's are 95% gtk, and all of the "desktop environments" are based on it, so it integrates well there. There are bindings for a whole bunch of languages including perl, python, and (!) php, but was originally C.

    Window has it's own native GUI API, doesn't it?
    Last edited by MK27; 03-17-2009 at 01:53 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  7. #7
    Registered User
    Join Date
    Mar 2009
    Posts
    3
    Ok thanks for the information guys, I appreciate it.

  8. #8
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by MK27 View Post
    Linux GUI's are 95% gtk, and all of the "desktop environments" are based on it, so it integrates well there. There are bindings for a whole bunch of languages including perl, python, and (!) php, but was originally C.
    So, are we gonna pretend that KDE doesn't exist?
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  9. #9
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    I actually don't use a DE at all because I like fvwm and virtual viewports on a giant desk with minimal clutter.

    I thought KDE was gtk because I use their Terminal, which appears to be gtk+ (it uses the gtk theme, anyway).

    But now I notice Terminal is not from KDE, because they call it a Konsole. It must be from XFCE (the one with the giant rat).

    So lets say 75%! What does KDE use, Qt or it's own deal?
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  10. #10
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    KDE uses Qt exclusively as far as I know.

    In fact, I'm pretty sure that KDE came about before GTK+; KDE was using the Qt library which was then a shareware application. A few people didn't like this (for freedom reasons) and so started Gnome. Then eventually Qt became open source and so Gnome lost the moral high ground.

    I probably have it wrong; look online if you want the real story.

    [edit] Personally, I'd probably say that at least 50% of Linux applications are Qt-based, as a rough guess. This is partially based on my assumption (possibly invalid) that C++ programs tend to use Qt instead of GTK+ and that C++ programs are a little more common than C ones these days.

    (FWIW, I'm biased. I prefer KDE these days. Sorry, zacs7.

    Gnome messed up my shortcuts taskbar one too many times, and I was using Konsole and KDevelop anyway, so I decided to switch to KDE.) [/edit]
    Last edited by dwks; 03-17-2009 at 02:57 PM.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  11. #11
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by dwks View Post
    KDE uses Qt exclusively as far as I know.
    KDE uses a lightly-patched Qt, and builds heavily on top of it. Most KDE apps use KDE-specific widgets inherited from Qt widgets. It's definitely Qt, but not "raw" Qt.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  12. #12
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    I still think it is beyond ridiculous that the window managers available for both KDE and GNOME ignore this if you put in xorg.conf:
    Code:
    SubSection "Display"
        Virtual 2560 1600
    Which to my mind, the virtual viewport is worth way,way more than any of the gimmicky candy and clutterbars.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  13. #13
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by MK27 View Post
    I still think it is beyond ridiculous that the window managers available for both KDE and GNOME ignore this if you put in xorg.conf:
    Code:
    SubSection "Display"
        Virtual 2560 1600
    Which to my mind, the virtual viewport is worth way,way more than any of the gimmicky candy and clutterbars.
    I don't know how a window manager could possibly override the virtual size. That is something implemented directly by the server. If they do somehow, that's dumb. I don't use virtual size, but I'll try this at home later.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  14. #14
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Thanks for the information. I've not really looked up on how to make C GUI's, are there are tools out there to make simple GUI's, like QT? It wouldn't have to be cross platform, as long as it could create GUI's on Windows thats fine, but it would be great if it was cross platform, or at least Windows and Linux anyway.

    Cheers.
    If you are using C then I'd recommend GTK+. You can use Glade3 to graphically design your GUI, which should do the job for simple GUIs, plus you can switch languages but keep your designs if you find C getting too tedious. Personally I prefer using pygtk as GUI programming is pretty dull and the processing generally isent very intensive. I'd rather get as much done as fast as possible... Maybe port the code to C when I have a prototype that I want to improve.
    Last edited by mike_g; 03-17-2009 at 03:44 PM.

  15. #15
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by brewbuck View Post
    I don't know how a window manager could possibly override the virtual size. That is something implemented directly by the server. If they do somehow, that's dumb. I don't use virtual size, but I'll try this at home later.
    Dumb indeed. I haven't bothered trying to find a way around (if there is one) because l prefer a blank desk except for a nice fat fvwm2 pager, and mouse button menus. Since the introduction of stuff like dbus and changes in "theme management", you have to do a bunch of hacks and tweaks to make gtk work there like it does in GNOME, et al. Sad.

    I've always thought the intent of the whole linux DE industry was to create an interface more appealing and comfortable for people coming from microsoft or mac. But I've never seen a real UNIX box either.

    I have gone back to using GNOME sometimes lately because I am supposed to be writing software for it, and it's nice and everything, but I still keep thinking, wow, it's sad the DE industry didn't get more creative (I mean in terms of functionality and different approaches, not just a "spinnning 3D cube" clone of the windows desktop). The "box" that GNOME, KDE, XFCE, etc. all seem to work within is way smaller than the potential box provided by X.
    Last edited by MK27; 03-17-2009 at 03:53 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed