excuse me if this question has been asked before than i am sorry i couldn't find it.
so i am ruining Ubuntu on my desktop computer and i have started c++ using code blocks i was wondering how do you make a GUI window for Linux or am i using the wrong tool for the job?

5 Years
Discussion Span
Last Post by Celtrix

You can use Qt. Do this in a terminal window:

$ sudo apt-get install libqtcore4 libqtgui4 libqt4-dev qt4-qmake qt4-doc qt4-demos qt4-assistant qt4-designer qtcreator qtcreator-doc

Some of the above might be redundant, but what the heck. And most of it is probably installed already as part of the distro or as dependency of other, already installed packages (since Qt is pretty wide-spread in Linux GUI world).

At that point, you should be able to make a project like this one:

#include <QApplication>
#include <QWidget>

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

    QWidget window;

    window.resize(250, 150);
    window.setWindowTitle("Simple example");

    return app.exec();

Save it to file "simple_example.cpp", go to that directory in a terminal, and run:

$ qmake -project
$ qmake
$ make
$ ./simple_example

If the above works, and it should (in the tradition of Linux being automatic and easy), then your setup is working, at least basically (you can browse synaptic for anything that starts with "libqt" for more plugins and add-ons, like opengl, sql, xml, svg, etc.). The above is just a simple example, the more usual approach is to design the GUI window using Qt Designer (by dragging and dropping GUI elements, instead of having to code everything in), save it to some .ui files, implement some event handlers (called "slots" in Qt), and create a qmake project file. It is a slightly more involved building process, but nothing to be afraid of.

There are plenty of tutorials on Qt. Like this, or that, or this.

Edited by mike_2000_17: n/a


I think the easiest way to make a window, or a simple game is using allegro4.2 or 4.3:

sudo apt-get install liballeg4.2-dev


sudo apt-get install allegro4.2-dev

Then open Code::Blocks and find linking in the settings adn put

`allegro-config --libs`

. Now you are ready to use Allegro:

#include <allegro.h>
/*On windows*/ #include <winalleg.h>
using namespace std;

int main(void) {
    allegro_init(); /initialize window
/ y,z - e.g. 640,480/800,600/1024,768/1280,960 ... as u wish it can be 100,1 too :D
/then find some sites with tutorials, but it is like pascal:
color = makecol(r,g,b);

You can code your GUI if you prefer but you can use Qt 4's Designer(good luck working with it I find it much easier to hard code it then to use the designer) as far a Gui libraries in general take a pick out of the litter you got GTK, QT4, WxWidgets as the main libraries and then you've got the cross platform SDL.

I can't really decide on which one is "easier" I like QT4's simplicity but alot of the documentation is obscure meaning your going to have to put it together which could take a while(depending on how complex the GUI needs to be) unless you use the gui QT designer but then you've got to learn how to use it.

if you just need a simple dialog you can use XDG

sudo apt-get install xdialog
pacman -Sy xdialog

for documentation on xdialog

man xdialog or xdialog --help or google.


thank you guys for all the help i'll see if it works :)


any time :P there are a couple of other ones but they aren't worth mentioning because they are kinda outdated and never worked on actively.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.