gtk - How to pass in a parameter
I have written in C in the past, but I find C++ a teensy little bit different.
I have taken the gtk "Hello World" example and modified it a bit. instead of outputting to stdout like that example, i want to output to a file. (I can manage that). However, I want to be able to pass in the filename as a parameter of the program. So I would run Code:
MyProg SomeFile How do I pick SomeFile from argv[1][0] and pass it through to the routine that picks up the button press, so that it knows what file to open. (Yes, I intend to Open-write-close on each button press to ensure that my data is writen safely - it won't be a performance problem. TIA Ian |
It would help if you provide what you have gotten so far. Fortunately for needs, GTK is in C.
You should already have char **argv in your [i]main[i] function. Setup a signal with that argv[1] or whatever one it is. [i]char *[i] or const char * can be converted to gpointer (which is void * typedefed). You handler (which is a C function pointer) can dereference the pointer to the pointer of the filename. |
OK. Here is what I have. 3 files plus Compiler output.
BTW A smiley creeps in to the code snippets where I have a : followed by an o. Code:
//$Id: ElTimeBody.h, Code:
//$Id: ElTimeBody.cc Code:
//$Id: ElTimemain.cc Code:
ElTimeBody.h: In member function �void ElapsedTime::setFileName(char)�: |
Your error seems to be referring to:
ElTimeBody.h:21: error: invalid conversion from �char� to �const char*� ElTimeBody.h:21: error: initializing argument 2 of �char* strcpy(char*, const char*)� so change: Code:
void setFileName(char FileName) {strcpy(_FileName, FileName);} Code:
void setFileName(const char *FileName) {strcpy(_FileName, FileName);} |
Thanks,
I knew it had to be soemthing like that - but there seemed to be about a million combinations, only one right, and I would try the failed ones over again. If my C wasn't so rusty, I guess I should have been able to work it out, Anyway, my program just sings now. Ian |
All times are GMT -5. The time now is 08:10 AM. |