LinuxQuestions.org
Visit Jeremy's Blog.
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-14-2014, 06:38 PM   #1
hnasr2001
Member
 
Registered: Nov 2012
Posts: 78

Rep: Reputation: Disabled
design a GUI interface with c++


What do I need in order to design a drop down menu and be able to draw a graph ( temp vs time) in c/c++?
I am using Centos OS.

Thanks
 
Old 09-14-2014, 07:45 PM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,235

Rep: Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914
I would look into gtk.
 
Old 09-14-2014, 09:21 PM   #3
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: Slackware
Posts: 8,497

Rep: Reputation: 3523Reputation: 3523Reputation: 3523Reputation: 3523Reputation: 3523Reputation: 3523Reputation: 3523Reputation: 3523Reputation: 3523Reputation: 3523Reputation: 3523
Or Qt.
 
Old 09-14-2014, 11:21 PM   #4
onebuck
Moderator
 
Registered: Jan 2005
Location: Summer Midwest USA, Central Illinois, Winter Central Florida
Distribution: SlackwareŽ
Posts: 13,238
Blog Entries: 29

Rep: Reputation: 2437Reputation: 2437Reputation: 2437Reputation: 2437Reputation: 2437Reputation: 2437Reputation: 2437Reputation: 2437Reputation: 2437Reputation: 2437Reputation: 2437
Moderator Response

Moved: This thread is more suitable in <Programming> and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 09-15-2014, 12:36 AM   #5
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,400

Rep: Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584
cimg.h
will do everything you need
http://cimg.sourceforge.net/

it is a graphics library in just the header

see the tutorial
http://cimg.sourceforge.net/referenc..._tutorial.html
and the screenshots of concept code
http://cimg.sourceforge.net/screenshots.shtml
 
Old 09-15-2014, 04:41 PM   #6
hnasr2001
Member
 
Registered: Nov 2012
Posts: 78

Original Poster
Rep: Reputation: Disabled
Regarding to CImg, I download the CImg_1.6.0_rolling140915.zip and moved the header to the /usr/include directory. I took one of the example and I compiled it with g++ and I am getting errors as described below;

This is the code;

/*
#
# File : tutorial.cpp
# ( C++ source file )
#
# Description : View the color profile of an image, along the X-axis.
# This file is a part of the CImg Library project.
# ( http://cimg.sourceforge.net )
#
# Copyright : David Tschumperle
# ( http://tschumperle.users.greyc.fr/ )
#
# License : CeCILL v2.0
# ( http://www.cecill.info/licences/Lice...ILL_V2-en.html )
#
# This software is governed by the CeCILL license under French law and
# abiding by the rules of distribution of free software. You can use,
# modify and/ or redistribute the software under the terms of the CeCILL
# license as circulated by CEA, CNRS and INRIA at the following URL
# "http://www.cecill.info".
#
# As a counterpart to the access to the source code and rights to copy,
# modify and redistribute granted by the license, users are provided only
# with a limited warranty and the software's author, the holder of the
# economic rights, and the successive licensors have only limited
# liability.
#
# In this respect, the user's attention is drawn to the risks associated
# with loading, using, modifying and/or developing or reproducing the
# software by the user in light of its specific status of free software,
# that may mean that it is complicated to manipulate, and that also
# therefore means that it is reserved for developers and experienced
# professionals having in-depth computer knowledge. Users are therefore
# encouraged to load and test the software's suitability as regards their
# requirements in conditions enabling the security of their systems and/or
# data to be ensured and, more generally, to use and operate it in the
# same conditions as regards security.
#
# The fact that you are presently reading this means that you have had
# knowledge of the CeCILL license and that you accept its terms.
#
*/

// Include CImg library file and use its main namespace
#include <CImg/CImg.h>
using namespace cimg_library;

#ifndef cimg_imagepath
#define cimg_imagepath "img/"
#endif

// Main procedure
//----------------
int main(int argc,char **argv) {

// Define program usage and read command line parameters
//-------------------------------------------------------

// Display program usage, when invoked from the command line with option '-h'.
cimg_usage("View the color profile of an image along the X axis");

// Read image filename from the command line (or set it to "img/parrot_original.ppm" if option '-i' is not provided).
const char* file_i = cimg_option("-i",cimg_imagepath "parrot_original.ppm","Input image");

// Read pre-blurring variance from the command line (or set it to 1.0 if option '-blur' is not provided).
const double sigma = cimg_option("-blur",1.0,"Variance of gaussian pre-blurring");

// Init variables
//----------------

// Load an image, transform it to a color image (if necessary) and blur it with the standard deviation sigma.
const CImg<unsigned char> image = CImg<>(file_i).normalize(0,255).blur((float)sigma).resize(-100,-100,1,3);

// Create two display window, one for the image, the other for the color profile.
CImgDisplay
main_disp(image,"Color image (Try to move mouse pointer over)",0),
draw_disp(500,400,"Color profile of the X-axis",0);

// Define colors used to plot the profile, and a hatch to draw the vertical line
unsigned int hatch = 0xF0F0F0F0;
const unsigned char
red[] = { 255,0,0 },
green[] = { 0,255,0 },
blue [] = { 0,0,255 },
black[] = { 0,0,0 };

// Enter event loop. This loop ends when one of the two display window is closed or when the keys 'ESC' or 'Q' are pressed.
while (!main_disp.is_closed() && !draw_disp.is_closed() &&
!main_disp.is_keyESC() && !draw_disp.is_keyESC() && !main_disp.is_keyQ() && !draw_disp.is_keyQ()) {

// Handle display window resizing (if any)
if (main_disp.is_resized()) main_disp.resize().display(image);
draw_disp.resize();

if (main_disp.mouse_x()>=0 && main_disp.mouse_y()>=0) { // Mouse pointer is over the image

const int
xm = main_disp.mouse_x(), // X-coordinate of the mouse pointer over the image
ym = main_disp.mouse_y(), // Y-coordinate of the mouse pointer over the image
xl = xm*draw_disp.width()/main_disp.width(), // Corresponding X-coordinate of the hatched line
x = xm*image.width()/main_disp.width(), // Corresponding X-coordinate of the pointed pixel in the image
y = ym*image.height()/main_disp.height(); // Corresponding Y-coordinate of the pointex pixel in the image

// Retrieve color component values at pixel (x,y)
const unsigned int
val_red = image(x,y,0),
val_green = image(x,y,1),
val_blue = image(x,y,2);

// Create and display the image of the intensity profile
CImg<unsigned char>(draw_disp.width(),draw_disp.height(),1,3,255).
draw_grid(-50*100.0f/image.width(),-50*100.0f/256,0,0,false,true,black,0.2f,0xCCCCCCCC,0xCCCCCCCC).
draw_axes(0,image.width()-1.0f,255.0f,0.0f,black).
draw_graph(image.get_shared_row(y,0,0),red,1,1,0,255,1).
draw_graph(image.get_shared_row(y,0,1),green,1,1,0,255,1).
draw_graph(image.get_shared_row(y,0,2),blue,1,1,0,255,1).
draw_text(30,5,"Pixel (%d,%d)={%d %d %d}",black,0,1,16,
main_disp.mouse_x(),main_disp.mouse_y(),val_red,val_green,val_blue).
draw_line(xl,0,xl,draw_disp.height()-1,black,0.5f,hatch=cimg::rol(hatch)).
display(draw_disp);
} else
// else display a text in the profile display window.
CImg<unsigned char>(draw_disp.width(),draw_disp.height()).fill(255).
draw_text(draw_disp.width()/2-130,draw_disp.height()/2-5,"Mouse pointer is outside the image",black,0,1,16).display(draw_disp);

// Temporize event loop
cimg::wait(20);
}

return 0;
}

and bellow is the error message;
[root@localhost src]# g++ graphic5.cpp
/tmp/ccZQ8o5F.o: In function `cimg_library::cimg::Mutex_info::trylock(unsigned int)':
graphic5.cpp.text._ZN12cimg_library4cimg10Mutex_info7trylockEj[cimg_library::cimg::Mutex_info::trylock(unsigned int)]+0x19): undefined reference to `pthread_mutex_trylock'
/tmp/ccZQ8o5F.o: In function `cimg_library::cimg::X11_info::X11_info()':
graphic5.cpp.text._ZN12cimg_library4cimg8X11_infoC1Ev[cimg_library::cimg::X11_info::X11_info()]+0x52): undefined reference to `XInitThreads'
/tmp/ccZQ8o5F.o: In function `cimg_library::cimg::X11_info::~X11_info()':
graphic5.cpp.text._ZN12cimg_library4cimg8X11_infoD1Ev[cimg_library::cimg::X11_info::~X11_info()]+0x1c): undefined reference to `pthread_cancel'
/tmp/ccZQ8o5F.o: In function `void cimg_library::CImgDisplay::_resize<unsigned char>(unsigned char, unsigned int, unsigned int, bool)':

Am I missing more library?
 
Old 09-15-2014, 05:38 PM   #7
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,400

Rep: Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584
Quote:
g++ graphic5.cpp
you look to be missing most of the build line

did you look at the makefile in cimg/exapmles/Makefile

you need to export a few libraries

start with this and go from there
Code:
g++ -o graphics5 graphic5.cpp -lX11 -lpthread -lm

Last edited by John VV; 09-15-2014 at 05:40 PM.
 
Old 09-16-2014, 11:16 AM   #8
hnasr2001
Member
 
Registered: Nov 2012
Posts: 78

Original Poster
Rep: Reputation: Disabled
Thanks Jon VV.

g++ -o graphics5 graphic5.cpp -lX11 -lpthread -lm worked and it create an output file.
When I tried to run the graphic5 (executable file) it said; instance(0,0,0,0,(nil),non-shared] CLmg<float>::load(): Failed to open 'img/parrot_original.ppm'

It seems still some files are missing
 
Old 09-16-2014, 12:02 PM   #9
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2018 CentOS6.10 CentOS7.5 + 50+ other Linux OS, for test only.
Posts: 17,107

Rep: Reputation: 3489Reputation: 3489Reputation: 3489Reputation: 3489Reputation: 3489Reputation: 3489Reputation: 3489Reputation: 3489Reputation: 3489Reputation: 3489Reputation: 3489
← #8 , @hnasr2001.
Quote:
Failed to open 'img/parrot_original.ppm'
CImg-1.6.0_rolling140915/examples/img/parrot_original.ppm :

You will have to move or copy 'img/parrot_original.ppm' to a location,
where it can be found.
-
Attached Files
File Type: txt CImg-1.6.0-file-list.txt (1.9 KB, 10 views)

Last edited by knudfl; 09-16-2014 at 12:07 PM.
 
Old 09-16-2014, 03:10 PM   #10
hnasr2001
Member
 
Registered: Nov 2012
Posts: 78

Original Poster
Rep: Reputation: Disabled
John, As you said, adding the links (-lX11 -lpthread) worked but how do you know what links to add?

I took another example and I am getting different error!
 
Old 09-16-2014, 03:32 PM   #11
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,400

Rep: Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584
i read the makefile and the error you posted
the error states what is missing
XInit
pthread

and the "-lm" is libm ( math)
that is a normal one to add with the NEWER versions of gcc
it is NOT inherited from other libraries any more

it may or may not have been needed


also you can put into "google" the error

"undefined reference to `XInitThreads'"

Last edited by John VV; 09-16-2014 at 04:01 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Is Local GUI interface possible to a remote NON-GUI server? drgheetar Ubuntu 3 07-01-2014 10:23 PM
LXer: Browsers, phishing, and user interface design LXer Syndicated Linux News 0 06-07-2006 06:54 AM
LXer: KOffice 2 User Interface Design Competition LXer Syndicated Linux News 0 12-22-2005 11:01 PM
GUI design kshaffer Programming 1 10-31-2004 05:14 AM
design webstorage user interface with java? ksgill Programming 0 07-07-2004 10:49 PM

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

All times are GMT -5. The time now is 01:16 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration