I made a basic text editor(called 'Note') in Qt on Arch Linux! so I built the project and made an installer using installjammer. now when I type note in terminal it opens the program. Now here is my question: if we use nano or leafpad or mousepad it take the path of the file opens it. Eg. nano /etc/fstab how can I do this in my program? do I need to edit something in the installer or in my codes? HELP ME! pls! ~Thanks!
相关问题
- Sorting 3 numbers without branching [closed]
- QML: Cannot read property 'xxx' of undefin
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
You might want to read the docs for QCoreApplication. Especially: QStringList QCoreApplication::arguments()
Get the filename from this ist, open the file.
Get the passed command line argument either directly in main() from the
argv
argument, or through QCoreApplication::arguments(). This is well documented and should be rather easy. The tricky part is actually opening the file. For that, you need to schedule a slot for running right after you call exec() on your QApplication instance. First, create a slot. For example, if you're subclassing QApplication, you can:In your MyApplication::checkCmdLine() function you get the arguments from QCoreApplication::arguments() and check whether a filename was passed. If yes, you open it.
Now you need to make sure that MyApplication::checkCmdLine() will run right after you call exec() on MyApplication. You do that in your main() function by using QMetaObject::invokeMethod(). For example:
If you're not subclassing QApplication, then you can implement the slot in some other QObject subclass and use QMetaObject::invokeMethod() on that instead.