QCommandLineParser

来源:互联网 发布:网络职业有哪些 编辑:程序博客网 时间:2024/05/23 00:54

D:\Qt\Qt5.5.1\Examples\Qt-5.5\widgets\widgets\imageviewer\imageviewer.pro

int main(int argc, char *argv[]){    QApplication app(argc, argv);    QGuiApplication::setApplicationDisplayName(ImageViewer::tr("setApplicationDisplayName"));    QCommandLineParser commandLineParser;    commandLineParser.addHelpOption();    commandLineParser.addPositionalArgument(ImageViewer::tr("[file]"), ImageViewer::tr("Image file to open."));    QStringList slArgs = QCoreApplication::arguments();    commandLineParser.process(slArgs);    qDebug()<<"slArgs="<<slArgs;    ImageViewer imageViewer;    QStringList slPargs = commandLineParser.positionalArguments();    qDebug()<<"slPargs="<<slPargs;    bool b1 = slPargs.isEmpty();    if (b1==false)    {        QString fileName=slPargs.front();        bool b2 = imageViewer.loadFile(fileName);        qDebug()<<"fileName="<<fileName;        if (b2==false)        {            return -1;        }    }    imageViewer.show();    return app.exec();}


0 0
原创粉丝点击