Results 1 to 5 of 5
Hi,
Is it possible to do the following in C/C++ in Linux:
Without direct linking (my program should NOT depend on Qt or GTK), display a GTK or Qt based ...
- 07-14-2010 #1Just Joined!
- Join Date
- Jul 2010
- Posts
- 2
Programmatically getting standard file dialog (C/C++)
Hi,
Is it possible to do the following in C/C++ in Linux:
Without direct linking (my program should NOT depend on Qt or GTK), display a GTK or Qt based file dialog.
The behaviour should be something like this when my program runs, when you want to open a file:
The program scans whether you have Qt installed. If so, it somehow manages to link itself to Qt (e.g. dynamically loading the .so file) and display its file dialog and get the path from it. If Qt wasn't found, it tries the same with GTK. If that also wasn't found, it displays a less powerful replacement dialog instead (better than nothing).
Or is there any other simple way in Linux to get a standard file dialog somehow (similar to when compiling for Windows you can very easily get its standard file dialog, no matter what version of Windows, in your code, even if your program doesn't use any other Windows GUI at all).
Thanks.
- 07-14-2010 #2Just Joined!
- Join Date
- Jul 2010
- Posts
- 53
the 'dialog' utility does just that - can display all kinds of widgets too (calendars, etc...)
here's a quick start:
dialog --output-fd 3 --fselect $HOME 20 10 3>/tmp/picked
when you select 'ok' to exit the file dialog, whatever you selected is written to /tmp/picked.
haven't used it in awhile but am sure you get the idea.
- 07-15-2010 #3Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
It is possible to do this using the dlopen() and related functions. That allows you to link in a shared library dynamically at runtime. However, you will still need to know what the classes/functions/signatures are that you will need to use. Typically, this is done by your own abstraction layer and associated implementation libraries that provide you a consistent interface. Otherwise, you will have link-time dependencies on the relevant UI libraries (Qt, GTK+, et al) and end up with them force-linked to your application. I have done this sort of development in the past, in order to provide the ability to dynamically link to different database, UI, and business rule implementations without needing to link to them specifically. However, this is sophisticated work and if you are not REALLY experienced in C++ programming and understand the ideas behind abstractions and patterns thoroughly, then you are probably biting off more than you can chew, as the saying goes. In any case, a LOT of upfront design work needs to be done (how are your UML skills?) before you are ready to get into the specifics of this sort of development. Bear in mind that when I first did this sort of work I had 10+ years intensive C and C++ development experience and was a principal engineer at a major software company.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 07-15-2010 #4Just Joined!
- Join Date
- Jul 2010
- Posts
- 2
What about different linux distro's: can those dynamic libraries be in different locations on different distro's, and if so, would one need to search all possible paths that some distro's might have to locate and dlopen the library?
I don't think I'd attempt the above, I was hoping there would be some standard way defined by the linux standard (if such standard even exists).
I'll look into the dialog utility to see if that works well.
EDIT: seems the dialog utility is not installed on Ubuntu by default... so the standard availability of it is already low
- 07-15-2010 #5Just Joined!
- Join Date
- Jul 2010
- Posts
- 53
not being in the 'default' installation means nothing - is why all linux variants have such good installers, plus who would want the million different possibilities in the 'default'???
there are several variants of this that have been around for awhile - from memory:
dialog, cdialog, whiptail, gdialog, kdialog, and Xdialog.
man -k dialog might show you have one of those installed already...
in addition to the shell utilities, most provide same thing as library so you can link them into your own code.
then there's always curses/ncurses that is available everywhere too.
if you want the Qt3, gtk, etc... libraries and are NOT going to statically link them into your application - then like eveyone else you must have some flexibility in being able to configure your application to different environments.


Reply With Quote