"It falsely claimed that options had to be passed first, which is not true." - You have right. I am noob and
I mislead.
I solve my problem with the order arguments and options. Also solve problem with "Usage: " information
by write my own help function.
I have last question about this post.
I started with this code
.h
#ifndef COMMANDLINEMANAGER_H
#define COMMANDLINEMANAGER_H
#include <QObject>
#include <QCommandLineParser>
#include <QCommandLineOption>
#include <QTextStream>
#include <QString>
#include <QDebug>
class CommandLineManager
: public QObject{
Q_OBJECT
public:
explicit CommandLineManager
(QObject *parent
= 0);
public slots:
void readInput();
private:
};
#endif // COMMANDLINEMANAGER_H
#ifndef COMMANDLINEMANAGER_H
#define COMMANDLINEMANAGER_H
#include <QObject>
#include <QCommandLineParser>
#include <QCommandLineOption>
#include <QTextStream>
#include <QString>
#include <QDebug>
class CommandLineManager : public QObject
{
Q_OBJECT
public:
explicit CommandLineManager(QObject *parent = 0);
public slots:
void readInput();
private:
};
#endif // COMMANDLINEMANAGER_H
To copy to clipboard, switch view to plain text mode
.cpp
#include "commandlinemanager.h"
CommandLineManager
::CommandLineManager(QObject *parent
) :{
}
void CommandLineManager::readInput()
{
while( 1 ) {
QCommandLineParser parser;
parser.addHelpOption();
parser.addPositionalArgument("command", "The command to execute." );
parser.parse( cmd );
if (command == "open") {
// best way to do this function?
// emit open( arguments and options ); ?
}
if( command == "copy" ) {
// check next option
}
}
}
#include "commandlinemanager.h"
CommandLineManager::CommandLineManager(QObject *parent) :
QObject(parent)
{
}
void CommandLineManager::readInput()
{
while( 1 ) {
QTextStream( stdout )<< "LockCommand" <<endl;
QTextStream( stdout )<< "# ";
QTextStream qin( stdin );
QStringList cmd = QCoreApplication::arguments()<< qin.readLine().split( " " );
QCommandLineParser parser;
parser.addHelpOption();
parser.addPositionalArgument("command", "The command to execute." );
parser.parse( cmd );
const QStringList args = parser.positionalArguments();
const QString command = args.isEmpty() ? QString() : args.first();
if (command == "open") {
// best way to do this function?
// emit open( arguments and options ); ?
}
if( command == "copy" ) {
// check next option
}
}
}
To copy to clipboard, switch view to plain text mode
main
int main(int argc, char *argv[])
{
CommandLineManager commandLineManager;
QMetaObject::invokeMethod( &commandLineManager,
"readInput", Qt
::QueuedConnection );
return a.exec();
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QCoreApplication::setApplicationName( "LockCommand" );
QCoreApplication::setApplicationVersion( "1.0" );
CommandLineManager commandLineManager;
QMetaObject::invokeMethod( &commandLineManager, "readInput", Qt::QueuedConnection );
return a.exec();
}
To copy to clipboard, switch view to plain text mode
I must use invokeMethod otherwise my readInput() function never allow to call app.exe().
Well I started?
And please tell me what is the best way to managment calls specific class /methods
for example when i read "open" with some arguments and options
I can connect in constructor with MyFileSystem class and then emit signal
if (command == "open") {
// best way to do this function?
// emit open( arguments and options ); ?
}
but if I will have np 50 functions I will have 50 if statement - it is good project?
Regards,
Bookmarks