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.
Glade is both a GUI designer, and to a lesser extent, a code generator. The code generated is a basic template that you finish off by completing the functionality of the event handlers for each widget. Depending on the version of Glade, the code generated is either C or C++. It is possible, in C/C++, to invoke shell commands using the system() function. For something as simple as creating a directory, it is easier to simply use library/system functions, such as mkdir().
I realize that none of this will make much sense unless you have some knowledge of C/C++. The C/C++ code generated by Glade won't make too much sense to a C/C++ programmer either, without having learned a bit about GTK and its underpinnings, which is quite well documented on the GTK website.
--- rod.
1. When I launch my app from a terminal, enter path_entry and click the start_button mplayer (not gmplayer btw!) open in the same terminal window I executed my app. Then when I kill mplayer with Ctrl-C this also kills my app. I've tried both fork and vfork but it doesn't seem to matter...
2. Why can't I do this
Code:
strcat( filespec, audiofile );
instead of
Code:
strcat( filespec, "audio.mp3" );
3. Is
Code:
gchar filespec[512];
supposed to be
Code:
gchar *filespec[512];
Thanks a lot for helping me understand how tis works!
On the question of Ctrl-C killing your mplayer & its GUI parent, I think that the Ctrl-C signal gets sent to all processes whose controlling terminal (or maybe whose stdin) is that TTY. If that is correct, there are two approaches that I think should work (and I am spitballing, here). The easiest, probably, is to trap, using the signal() system call, the Ctrl-C signal, and handle it in some graceful way (probably ignoring it) in your GUI. I think an alternative, and probably a more graceful arrangement, would be to pipe() mplayer's stdin & stdout to your GUI. Then, create a button that issues a signal to the mplayer child process to kill it. You could also use this to grab mplayer's stdout, and display it in a GUI window, winning favor from your application's users, accolades from your colleagues, fame and glory (sorry, no cash; this is open source).
The exact mechanics of the first method can be mostly gleaned from the man pages for signal & kill(2). The second arrangement is a bit more complex, but for a decent description of how to use pipe()'s, I like Beej's Guide to IPC.
Code:
strcat( filespec, audiofile );
Should be perfectly valid, as long as the arguments are correctly initialized.
Code:
gchar filespec[512];
is an array of characters. Essentially, storage for a string.
Code:
gchar *filespec[512];
is an array of pointers to characters. Essentially, a bunch of pointers to one of those which is declared above. Until initialized, each of said pointers is a pointer to somewhere completely random, and dereferencing it would be likely to cause a Bad Thing.
Before calling string functions, don't forget to
Code:
#include <string.h>
GTK may have some wrapper library function that would possibly be better to use as an alternative.
Is there someone missing - do I need everyone? I've just added them on the fly beliving more is better :-)
And - is the syntax correct? I've seen both <name.h> and "name.h" in tutorials....
It looks like you need to understand what the argv[] argument is for. This is the list of arguments passed to the program. Each of the arguments, pointers to strings, should be initialized to point to strings that make some sense in the context of the program being launched. In the case of execv(), the argument list is terminated by a NULL pointer, '(char *)0'. The first element of argv[] should be a duplicate of the 'path' argument. Failing to correctly initialize the elements of your argv[] argument list will result in a Bad Thing.
To put the explanation in a different context, the argv[] array corresponds to '$1', '$2', '$3'.... in a bash script. To confirm that your arguments are being correctly configured, you could make a testbed launcher that launches a bash script, and that bash script could simply echo its commandline arguments. If the output from that looks good, then use that format for your real program launcher.
I think your last question is a symptom of the same problem.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.