Simple cross-platform C GUI library
James Stanley

I am looking for a GUI library with some very strict requirements:

- It must run on at least Linux and Windows
- It must be possible to use in C
- It must not interrupt execution of the program
EDIT: - It should be fairly simple to incorporate into an existing program

The third requirement means that the program can continue to handle network traffic whilst asking the user to enter some information.

Matthew Leverton

"Not ugly" wasn't a requirement, so why not use Allegro's?

James Stanley

Allegro's isn't simple for this task since it's not an allegro-based program.
It is currently a text-based tunneling proxy, but I wanted to put a GUI on the client to make it look nicer.

EDIT:
But I would be willing to use it if it's the only option

EDIT2:
I forgot to mention fairly simple as a requirement.

le_y_mistar

i believe QT is crossplatform, so is GTK..just learn GUIs and event handling, that's the most straightforward way.

James Stanley

Qt is C++, so I wouldn't consider using it (although I like how it looks). I'll see the GTK docs some time to see if I'd get on with it. Thanks.

kronoman

what about using a text GUI? like ncurses based or something... good old conio.h? :P

X-G

wxWidgets.

Vanneto

I tried to download wxWidgets, but I couldnt find any binary packages for Windows. Compiling would take all night I reckon. Can anyone tell me where to get binary packages?

Goalie Ca
Quote:

The third requirement means that the program can continue to handle network traffic whilst asking the user to enter some information.

this is commonly known as threading :P

I recommend GTK but wxWidgets should fit the bill. I haven't found a wxWidgets bin for windows though. It is not too hard to compile.

Thomas Fjellstrom

Wx is also C++.

BAF

GTK is horrid looking. Compiling wx doesn't take too long, it took probably 3 hours on my old 366mhz box. What's wrong with C++?

kazzmir
Quote:

GTK is horrid looking.

Well.. I like it. At least how it looks. I tried my hand at writing a GTK app once but the whole framework just seems to cumbersome.

Archon

I think that GTK with the Ubuntu theme looks quite nice.

MiquelFire

I tend to not like GTK apps on Windows. It's one of the two reasons I was running XChat via NX during Speedhack. (Other being that last I checked, you needed to pay to get a precompiled version for Windows from the developers, or hope someone has a binary that may not crash often because of a plugin that happens to only work well with the official binary, or something stupid like that.)

Mokkan
Quote:

What's wrong with C++?

Didn't you hear what Linus Torvalds said? >:(

But seriously, if you're hellbent on using C, GTK is really your main option.

James Stanley
Quote:

What's wrong with C++?

I don't and have never liked the C++ way. Presumably, as Qt is a C++ library, it does things the C++ way.

EDIT:
By that I mean I dislike the STL and classes.

Jonatan Hedborg

Let's just leave it at "he wants to use C" and not start yet another C vs. C++ thread...

James Stanley

The thread can be closed now, anyway, since I have more or less decided on GTK.

Carrus85
Quote:

I don't and have never liked the C++ way. Presumably, as Qt is a C++ library, it does things the C++ way.

Well, in that case, you can use the "C++ way" for everything Qt/wx provides, but do everything else the C way (with extra nitpicks provided to you courtesy of C++!) to just stick to the man!

I guess I don't get the whole "I want to use C because the C++ way of doing things is annoying" when "The C++ way of doing things is (almost; there are a handful of corner cases) a strict superset of the C way of doing things."

Seriously, there is no reason why you cannot use malloc/free, no exceptions, only functions, and use the wonky (type_to_cast_to_here) syntax.

James Stanley

You don't seem to understand.
I am not happy to use C++ just because that's what library X uses. Even if I only use it to interface with the library (and there is no point in writing a C wrapper).
I am happy to go with GTK.
Thank you to everone.

Carrus85

Suit yourself. (I'm not trying to be condescending or anything, I'm just saying, in most cases, you can compile C code as C++ code just fine with minimal "fixup" work (or so my experiences seem to indicate)).

James Stanley

Sorry to be so harsh in my reply.
I was getting a little frustrated because I thought the thread should have ended by now.
I've compiled C code as C++ before, so I knew that. I just think that if I'd be happy using the GUI as C++ I'd do the rest of the program in C++.

Thomas Fjellstrom
Quote:

as Qt is a C++ library, it does things the C++ way.

Actually, it does things the Qt way. It provides its own sane platform to work from, so you don't even have to touch the stl or stdlibc++.

The only reason I decided to work with C++ more often was because Qt is C++, and has un-stupid classes (like a String class that's actually usefull), and a kick ass GUI component.

Qt 4 is much more than just GUI, it has several modules, including the following:

QtCore      Core non-GUI classes used by other modules
QtGui       Graphical user interface components
QtNetwork   Classes for network programming
QtOpenGL    OpenGL support classes
QtSql       Classes for database integration using SQL
QtScript    Classes for evaluating Qt Scripts
QtSvg       Classes for displaying the contents of SVG files
QtXml       Classes for handling XML
QtDesigner  Classes for extending Qt Designer
QtUiTools   Classes for handling Qt Designer forms in applications
QtAssistant Support for online help
Qt3Support  Qt 3 compatibility classes
QtTest      Tool classes for unit testing

Its quite the inclusive platform. It also supports Windows, X, and MacOS. As well as most Qt code can work under QTopia (mobile device version, ie phones and tablets) possibly with some changes.

Archon

Qt4 is like the Java class library for C++.

Thomas Fjellstrom

Qt4 is like the CPAN for C++ ;)

Qt4 actually makes C++ feel a little like Perl for me, in the RAD department that is.

axilmar

Qt should be adopted by the C++ community as the defacto C++ SDK.

Archon
Quote:

Qt should be adopted by the C++ community as the defacto C++ SDK.

Unfortunately, that'd GPL everything done with C++. Unless Tomasu can purchase us all licences.

Thomas Fjellstrom

Heh, I wish. I can't afford my own licence at the moment.

BAF

C# still beats Qt, IMO as far as RAD goes. I've not used Qt much, but I don't think it has a fully integrated GUI designer and kick ass IDE. Of course, the caveat there is that its primarily Windows target audience. :-/

Thomas Fjellstrom

The Qt designer fully integrates into MSVC and Eclipse.

MiquelFire

Though, for MSVC (unless they changed recently) you have to pay anyway. (MSVC IDE was not free when it went dual license between their pay and GPL)

Thomas Fjellstrom

Pretty much. But you have to pay for the good C# ide anyhow.

Archon
Quote:

Pretty much. But you have to pay for the good C# ide anyhow.

...or be a part of a university course that is linked with Microsoft :)

Actually, I suggested to one of my lecturers to ask if he could discuss about the .odf standard -- perhaps to replace the widespread .doc standard (it was a far shot, I know). He said that it may be difficult because of my university's ties with Microsoft. :-X

axilmar

Getting back to the original topic, there is not a simple GUI library for C. My emphasis on simplicity...I think the simplest interface for a C-based GUI is to use message passing, ala Allegro. The GTK object-orientation mechanism bolted onto C is horrible. In other words, a really simple C GUI would be something like this:

#include <gui.h>

int main() {
    Widget window = create_widget(&window_class, NULL,
        PROPERTY_TEXT, "a window",
        NULL);
    Widget button = create_widget(&button_class, NULL,
        PROPERTY_TEXT, "Click me",
        EVENT_CLICK, event(&window, MESSAGE_CLOSE, NULL),
        NULL);
    do_event_loop(window);
}

Making new widgets should be as simple as:

1enum MY_WIDGET_PROPERTIES {
2 PROPERTY_DATA = WIDGET_PROPERTY_LAST,
3 MY_WIDGET_PROPERTY_LAST
4};
5 
6 
7struct _MY_WIDGET {
8 _WIDGET widget;
9 int data;
10};
11 
12static int _my_widget_proc(_WIDGET *wgt, int msg, void *data) {
13 _MY_WIDGET *m = (_MY_WIDGET *)wgt;
14 
15 switch (msg) {
16 case MESSAGE_PAINT:
17 ...bla bla paint widget
18 break;
19 
20 case MESSAGE_SET_PROPERTY:
21 ...bla bla set property
22 break;
23 }
24 
25 etc
26}
27 
28WIDGET_CLASS my_widget_class = {
29 "my_widget",
30 sizeof(_MY_WIDGET),
31 _my_widget_proc
32};

This style of object orientation is much more preferrable than the style of GTK. Unfortunately there is no such cross platform GUI for C. The QNX's Photon GUI uses this design. Motif/Lesstif uses this design as well, but there are lots of horrible things in them.

X-G

I can honestly say this is why I try to do as much of my GUI stuff as possible in Python with wxPython these days. It's so much more comfortable.

BAF

What's wrong with the express versions of VC# or VC?

HoHo

Officially QT doesn't support express versions, also they lack profiler, a thing I really need for my work.

juvinious

Well it seems that might change

MiquelFire

Sweet! I'm so going to use that! Though I'll still use MinGW to make the release copy however.

Thread #593252. Printed from Allegro.cc