Qt interactive console application. QCommandLineParser
-
I want make Qt interactive console application. In this application I want make interactive argument parsing like in parted.
I think this is one of the most popular interface in Qt world, isn't it? So I want to use pattern. I am interesting in example.
I was surprised, I can't find articles and well-descripeted examples and no official documentation for interactive console application...
There is only one short example-message in forum.- It use while(1) but is it good? Looks I should prefer to use signal-slot system (how?).
- How I can use Up, Down arrows to use previously used cmd like in Bash? Can I use QCommandLineParser capability for it or I should make cmd push-pop archive by my code?
I have ideas, but I want to use pattern. I am interesting in example.
-
I read about GNU readline. I think this is C code project with big legacy... I read about modern linenoise. But it's also C code project...
Then I try replxx. replxx is C++ project, I can easy integrate it in my Qt code. This is my example for replxx
-
Well, for one thing,
QCommandLineParser
isn't for this. TheQCommandLineParser
is for parsing parameters specified to your program on the command line (like the-a -b -c
in./myapp -a -b -c
). It has nothing to do with parsing input to the application while it is running.See the documentation for details: https://doc.qt.io/qt-6/qcommandlineparser.html
The rest of your question is too broad for me to answer, really.
Normally you'd just write a loop with the obvious logic, like (not real code):
loop forever { // step 1: read command from stdin // step 2: parse command and do something // step 3: print any output from command }
If you want the ability to e.g. cycle through command history with the up arrow, you'll have to either write that logic yourself or use an existing third-party library to read input. A common one is GNU readline.
Good luck.
-
@DungeonLords said in Qt interactive console application. QCommandLineParser:
I want make Qt interactive console application. In this application I want make interactive argument parsing like in parted.
I think this is one of the most popular interface in Qt world, isn't it? So I want to use pattern. I am interesting in example.
I was surprised, I can't find articles and well-descripeted examples and no official documentation for interactive console application...
There is only one short example-message in forum.- It use while(1) but is it good? Looks I should prefer to use signal-slot system (how?).
I don't think command line interface applications written with Qt are particularly popular.
If you want to learn Qt, learning how to use signals and slots is important. Whether it is necessary for this case isn't clear. Are there sources of events other than the user, such as timers or network traffic?
- How I can use Up, Down arrows to use previously used cmd like in Bash?
Using arrow keys will require turning off 'canonical' or 'cooked' mode for the terminal. I am unaware of anything in Qt that will help here. There is a BsdKeyboard plugin that may provide some inspiration and guidance.
With a posix system, 'raw' mode can be enabled with tcsetattr(). Character echoing should probably also be disabled in favor of character echoing controlled by the application. This includes deleting previously printed characters when required. I don't know what the equivalent API is for Windows.
Can I use QCommandLineParser capability for it or I should make cmd push-pop archive by my code?
If you want to structure the input as individual command lines, QCommandLineParser could work as a string parser.
-
I read about GNU readline. I think this is C code project with big legacy... I read about modern linenoise. But it's also C code project...
Then I try replxx. replxx is C++ project, I can easy integrate it in my Qt code. This is my example for replxx
-