LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-16-2004, 04:05 PM   #1
The Oate
Member
 
Registered: May 2004
Location: Massachusetts
Posts: 134

Rep: Reputation: 16
GUI for C++


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.
 
Old 09-16-2004, 04:15 PM   #2
sether
Member
 
Registered: Aug 2004
Posts: 695

Rep: Reputation: 31
i know kdevelop has some tools for that if you're using kde.
 
Old 09-16-2004, 04:17 PM   #3
nhs
Member
 
Registered: Aug 2003
Location: Edinburgh, Scotland
Distribution: Gentoo
Posts: 246

Rep: Reputation: 30
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:

#include <qapplication.h>
#include <qmainwindow.h>

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.

Last edited by nhs; 09-16-2004 at 04:20 PM.
 
Old 09-16-2004, 04:31 PM   #4
The Oate
Member
 
Registered: May 2004
Location: Massachusetts
Posts: 134

Original Poster
Rep: Reputation: 16
Will what you suggest work in GNOME or would I have to use different header files for it?
 
Old 09-16-2004, 04:34 PM   #5
mai1man
LQ Newbie
 
Registered: Aug 2004
Distribution: suse 9.1 pro, Slack 10.0, Gentoo 2004.2
Posts: 24

Rep: Reputation: 15
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.
 
Old 09-16-2004, 04:36 PM   #6
nhs
Member
 
Registered: Aug 2003
Location: Edinburgh, Scotland
Distribution: Gentoo
Posts: 246

Rep: Reputation: 30
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:

g++ -o app -I/usr/lib/qt3/include file.c -L/usr/lib/qt3/lib -lqt-mt
 
Old 09-17-2004, 02:50 AM   #7
suowei1979
LQ Newbie
 
Registered: Sep 2004
Location: BeiJing,China
Distribution: Red Hat
Posts: 25

Rep: Reputation: 16
You can use some GUI library:QT,gtk,minigui,fltk,microwindow and so on
 
Old 09-17-2004, 03:54 AM   #8
melinda_sayang
Member
 
Registered: Dec 2003
Location: Petaling Jaya
Distribution: Ubuntu
Posts: 475

Rep: Reputation: 31
gtkmm, qt, and wxwindows. Use one of these C++ GUI library because the support is good and they are popular.
 
Old 09-17-2004, 03:46 PM   #9
The Oate
Member
 
Registered: May 2004
Location: Massachusetts
Posts: 134

Original Poster
Rep: Reputation: 16
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.
 
Old 09-17-2004, 05:34 PM   #10
alexrait1
Member
 
Registered: Jul 2003
Location: Israel
Distribution: slackware current kernel 2.6.9
Posts: 70

Rep: Reputation: 15
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:
Code:
make
 
Old 09-17-2004, 06:00 PM   #11
The Oate
Member
 
Registered: May 2004
Location: Massachusetts
Posts: 134

Original Poster
Rep: Reputation: 16
What's a ui file?
 
Old 09-17-2004, 06:07 PM   #12
The Oate
Member
 
Registered: May 2004
Location: Massachusetts
Posts: 134

Original Poster
Rep: Reputation: 16
Nevermind, I've got it working. Thanks
 
Old 09-18-2004, 10:58 PM   #13
johnMG
Member
 
Registered: Jul 2003
Location: CT, USA
Distribution: Debian Sarge (server), Etch (work/home)
Posts: 601

Rep: Reputation: 32
You might also have a look at TOAD
http://www.mark13.org/toad/
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[Ubuntu GUI] Changing GUI from Gnome to wmaker MangaManiac Linux - Laptop and Netbook 8 05-08-2005 03:17 PM
KDE gui vs. Gnome GUI Curt6000 Linux - Newbie 11 11-10-2004 01:37 PM
Isn't Windows 95 or 98 a better GUI solution for old machines than an old Linux GUI lynchmob09 General 10 04-20-2004 01:24 AM
no more gui? fitzov Linux - Newbie 5 12-28-2003 06:53 AM
Won't go into GUI Micro420 Mandriva 1 08-23-2003 12:36 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration