Unix command slot creation
-
wrote on 3 Oct 2011, 06:33 last edited by
hi.. Is there any way in qt to execute unix commands like "pwd " when a button pressed
-
"QProcess":http://developer.qt.nokia.com/doc/qt-4.7/qprocess.html should be your friend here.
-
wrote on 3 Oct 2011, 07:50 last edited by
"QDir":http://doc.qt.nokia.com/4.7/qdir.html#current might be a better option for your example command. But in general, sierdzio is right.
-
wrote on 3 Oct 2011, 08:22 last edited by
I think you should avoid to create such a slot. The beauty of Qt is that the library is platform independent, so if you need to get runtime informations such as the working directory or alike you should use the library services, and not platform specific commands that are going to tie your application to a specific execution environment.
-
wrote on 3 Oct 2011, 08:49 last edited by
my application is not only for path finding..like cp -r sourcefile destinationfile like this type of commands also...
-
wrote on 3 Oct 2011, 09:28 last edited by
I strongly suggest to avoid running processes like the above directly, or your application will be strictly tied to the unix environment, and maybe to a linux one!
Use QFile for managing copies, QDir for managing paths and classes alike as much as you can. -
fluca1978, I think you're overreacting a little bit. phani448 seems to have already chosen their way of doing it. It is, of course, possible to use native tools on all platforms by simply specifying different names for tools, depending on the host OS (Qt has a set of OS related #defines that can be used here), and it will work just as well. It might not be the best option in your view (mine too, in fact, at least when it comes to trivial stuff like cp -r or pwd), but the subject here revolves around HOW to run native commands, not WHETHER to use them.
-
wrote on 3 Oct 2011, 10:40 last edited by
Sorry, I was not saying it is absolutely a bad idea to use QProcess, but that it could be a bad idea for a lot of cases where Qt already provides a wrapping for doing the same task.
-
[quote author="fluca1978" date="1317638423"]Sorry, I was not saying it is absolutely a bad idea to use QProcess, but that it could be a bad idea for a lot of cases where Qt already provides a wrapping for doing the same task. [/quote]
And you're perfectly right here :) Cheers.
1/9