ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How would I go about adding a GUI to a really simple C++ program I've written? I've done a lot of programming in the past, but it's always been command line based and I wanted to branch out to graphical stuff as well.
There are different libraries which will allow you to implement GUIs however (in my opinion) one of the simplest to use and a very well documented option is Qt. This example just displays a window:
int main(int argc,char **argv)
{
QApplication a(argc,argv);
QMainWindow w;
a.setMainWidget(&w);
w.show();
return a.exec();
}
The trolltech documentation site(http://doc.trolltech.com/3.2/index.html) has a number of tutorials and docuumentation about all the classes available. As a further bonus extending to use KDE specific functionality is very easy.
You should try glade. It's a easy way to create GUI's using the Gtk library. Although it doesn't compile directly code for C++, it is generated by gtkmm, and you can set your glade for that.
The code will run under GNOME however will have the Qt theme as opposed to the GNOME theme. Similarly a program developed using the GNOME libraries would still look like a GNOME program in KDE. This shouldn't prove a problem and provided you have Qt installed (potentially may require devel packages) compiling shouldn't present any major difficulties. I generally compile with the command along these lines:
I installed QT into a directory called QT3. How do I compile a program using the qt header files? When I try to, I get no such file or directory for the .h files I'm trying to include.
You should work as much as possible with designer-qt whenever it concerns gui. The simplest project will be if you create the ui file and add a main.cpp file like the one above.
Qt tools, such as moc will generate later a .h file for it, so you can suppose it's already there, how? you will subclass the base class which is the form this ui file represents (includes).
So let's see what we have: some cpp, h, ui, ui.h and a main.cpp file that are located in some folder.
You run
Code:
qmake -project
=> that will make a new pro file.
Then you run
Code:
qmake
that will generate the make file
And the last one of course:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.