Help - Search - Members - Calendar
Full Version: C++ Question
OESF Forums > Distros, Development, and Model Specific Forums > Everything Development > Linux Applications
Capn_Fish
I'm making a program for the Z that I need to take a variable and use it as part of a "system (xxxx)" command (or some other command to have the program call another command with args). How do I do that? Sorry if a) this is really obvious or cool.gif this question doesn't make sense. I have very little C++ knowledge, but am trying to learn.

Links to a solution would also be appreciated.

Thanks in advance.
Meanie
QUOTE(Capn_Fish @ May 2 2007, 11:00 AM)
I'm making a program for the Z that I need to take a variable and use it as part of a "system (xxxx)" command (or some other command to have the program call another command with args). How do I do that? Sorry if a) this is really obvious or cool.gif this question doesn't make sense. I have very little C++ knowledge, but am trying to learn.

Links to a solution would also be appreciated.

Thanks in advance.
*


sprintf is your friend smile.gif
Capn_Fish
OK, I got everything sorted out (for the moment).

Thanks for the response.
Capn_Fish
New question: Is jumping in WAY over my head and trying to figure out GUI programming with GTKmm with very little C++ knowledge not recommended (for reasons other than the frustration factor)?
Meanie
QUOTE(Capn_Fish @ May 11 2007, 08:17 AM)
New question: Is jumping in WAY over my head and trying to figure out GUI programming with GTKmm with very little C++ knowledge not recommended (for reasons other than the frustration factor)?
*


i'd recommend trying out the qt3 widgets first. took me 3 days to learn qt3 api and write pdaXcfg. i did all this natively on the z so compilation and debugging was much slower. you can actually install qt3 on a pc, compile and debug your app on the pc and when it all looks ok, recompile on the zaurus. there also is qt designer, a gui to create qt3 guis which also works on either pc or zaurus... gtkmm is a bit harder to learn...
Capn_Fish
QUOTE(Meanie @ May 10 2007, 07:15 PM)
QUOTE(Capn_Fish @ May 11 2007, 08:17 AM)
New question: Is jumping in WAY over my head and trying to figure out GUI programming with GTKmm with very little C++ knowledge not recommended (for reasons other than the frustration factor)?
*


i'd recommend trying out the qt3 widgets first. took me 3 days to learn qt3 api and write pdaXcfg. i did all this natively on the z so compilation and debugging was much slower. you can actually install qt3 on a pc, compile and debug your app on the pc and when it all looks ok, recompile on the zaurus. there also is qt designer, a gui to create qt3 guis which also works on either pc or zaurus... gtkmm is a bit harder to learn...
*


What about FLTK?

And I'd assume it'd take me much longer than 3 days if that's how long it took you, as I don't have the background you do wink.gif
pgas
Depending on you background, you might want to try an easier
language first, say python, ruby....

C++ is probably the most complicated language out there (even if qt makes things easier, and probably gtkmm also).

Don't worry about performances, even the Zaurus is perfectly able to run python applications, and if your application is good or is something people are missing, they will use it anyway.
Meanie
QUOTE(pgas @ May 11 2007, 03:54 PM)
Depending on you background, you might want to try an easier
language first, say python, ruby....

C++ is probably the most complicated language out there (even if qt makes things easier, and probably gtkmm also).

Don't worry about performances, even the Zaurus is perfectly able to run python applications, and if your application is good or is something people are missing, they will use it anyway.
*


yeah. python, perl. they all run reasonably fast on the Z, so use the easiest one. python is already pre-installed on pdaXrom since the config tools use it so less stuff needs to be installed in order to run your apps, whereas if you write things in fltk or something else, you will need to install extra libs.

the main reason I choose to learn QT3 instead of python is the load speed. Since qt3 is just additional apis for c++, they are compiled binaries and qt3 libs already exist in pdaXrom (Package Manager and PPP tools for example are QT3) so nothing extra needs to be installed. python and perl are interpretors, you need to have those installed and each app written in those languages requires the interpretor loaded before it loads the app, so essentially more loading time and memory used. since qt3 is a compiled shared library, ie, .so, it only needs to be loaded once and can be shared amongst multiple qt apps.
hence if you want your apps to load very fast, use GTK+ ( C ), not gtkmm (C++) because C is slightly faster than C++ and gtk+ is already installed and loaded by most X apps. qt3 also loads pretty fast, but may be unloaded if no qt3 apps have been used for a while and because the ratio of gtk+ apps is much higher than qt3 apps, chances are the gtk+ libraries are never unloaded and always there...
perl and python apps which dont use gui are also quite fast to load, however, in order to use the GUI, those interpretors need to load a bridge, ie python gtk bindings which is pygtk.

there is not much difference in execution time for the binaries/scripts written in those languages, but the loading time of the interpretors/extra libraries adds additional time for the application to start hence, the perceived speed of the application is slower.

so i chose QT3 because it uses C++ which is Object Oriented instead of procedural like in C, and it loads faster because it is supported by a mutli-threaded shared libraries and already pre-installed on pdaXrom (qt-mt.so). also, the QT3 widget are quite easy to use and make it much easier than standard C/C++ or GTK+
pgas
I wonder if pyqt and python + gtk-server ( http://www.gtk-server.org/ )
suffer from the same startup overhead
Capn_Fish
Nah, I like C++, and I'll look into QT3.

Thanks.
Capn_Fish
You need -devel libs to compile QT3 on the Z, no? Do these exist, or should I do the dev work on my larger computer?

Thanks.

EDIT: I'm going to put my GUI development on hold until I solidify my C++ base. Thanks for the help, and I'll probably need more in the future.

As a side note, FLTK looks pretty good...
Capn_Fish
Is there any way to only use one string-like variable (char[xyz] or string) in my code? Some things complain if I use a char[xyz], but not a string, others work the opposite way, and it would be easier to just use one type instead of converting back and forth.

Thanks.
Meanie
QUOTE(Capn_Fish @ Jun 9 2007, 11:13 AM)
Is there any way to only use one string-like variable (char[xyz] or string) in my code? Some things complain if I use a char[xyz], but not a string, others work the opposite way, and it would be easier to just use one type instead of converting back and forth.

Thanks.
*



sounds like QString is what you want smile.gif
Capn_Fish
QUOTE(Meanie @ Jun 8 2007, 09:50 PM)
QUOTE(Capn_Fish @ Jun 9 2007, 11:13 AM)
Is there any way to only use one string-like variable (char[xyz] or string) in my code? Some things complain if I use a char[xyz], but not a string, others work the opposite way, and it would be easier to just use one type instead of converting back and forth.

Thanks.
*



sounds like QString is what you want smile.gif
*


I'm not using QT. Is that an issue?

Is it possible to just use either strings or character arrays?
Meanie
QUOTE(Capn_Fish @ Jun 9 2007, 12:57 PM)
QUOTE(Meanie @ Jun 8 2007, 09:50 PM)
QUOTE(Capn_Fish @ Jun 9 2007, 11:13 AM)
Is there any way to only use one string-like variable (char[xyz] or string) in my code? Some things complain if I use a char[xyz], but not a string, others work the opposite way, and it would be easier to just use one type instead of converting back and forth.

Thanks.
*



sounds like QString is what you want smile.gif
*


I'm not using QT. Is that an issue?

Is it possible to just use either strings or character arrays?
*



either convert between them, or design your apps better to just use only methods that supports either one of them only.
alternatively, use a easier to use framework which has already solved this problem for you...
pelrun
Use std::string wherever you can (and pass const/non-const references to all your functions), it will make your life much easier. But there will be cases where you need to convert, generally for third-party library functions.

Conversion is pretty darn trivial, though.

1) .c_str() to get a const pointer to a std::string, you can use that straight in the function call e.g. someFunction(myString.c_str());

2) create an old style char buffer in local scope for functions which modify their contents, then assign the buffer to the std::string you're using in the rest of your code. std::string is smart enough to understand "myStdString=myCString;"
Snappy
QUOTE(Capn_Fish @ Jun 9 2007, 10:57 AM)
QUOTE(Meanie @ Jun 8 2007, 09:50 PM)
QUOTE(Capn_Fish @ Jun 9 2007, 11:13 AM)
Is there any way to only use one string-like variable (char[xyz] or string) in my code? Some things complain if I use a char[xyz], but not a string, others work the opposite way, and it would be easier to just use one type instead of converting back and forth.

Thanks.
*



sounds like QString is what you want smile.gif
*


I'm not using QT. Is that an issue?

Is it possible to just use either strings or character arrays?
*



I guess there is no easy way out but to convert them back and forth. Not too familiar with the string definition in QT3, but there might be some cast members that return a pointer from string that can be used as a char pointer in some functions.

Using MFC (Microsoft Foundation Classes) as an example,

CString sMyText;
char szMyText[100];
char * lpszMyText;
sMyText = "Some data here";
lpszMyText = sMyText.GetBuffer(sMyText.GetLength());
// Use lpszMyText

strcpy(szMyText, lpszMyText);

lpszMyText = NULL; // Not required but good practise to null the pointers

// Release buffer pointer
sMyText.ReleaseBuffer();

Hope this make sense. smile.gif
Capn_Fish
Slowly working around my problem, but I have another question:

There is a clear() function to strings. Is there a similar function for character arrays?

Sorry if that's a really dumb question, but I'm still new to C++.

Thanks in advance.
Capn_Fish
Never mind, I worked around it.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2014 Invision Power Services, Inc.