Extract parameters from string, included quoted regions, in Qt

前端 未结 3 1448
梦如初夏
梦如初夏 2021-01-22 07:27

I have a Qt5/C++ program which receives a QString containing a program name and possibly parameters. I need to split this QString into multiple strings. For example, the strin

3条回答
  •  面向向阳花
    2021-01-22 07:38

    I'm not familiar with the particulars of Qt, however with a quick look at the documentation for QString, here, I believe that the following code should work (albeit inefficiently).

    #include
    #include
    
    vector list; //vector used for variable length parameter requirements
    QString args; //The arguments string
    bool quoteFlag = false;
    for(int i=0; i

    Again, I do not use any Qt libraries, and this code is untested, but, if I understand the documentation, it should work.

    As far as the -p 4 bit goes, that is not possible with your current syntax for the other arguments.

提交回复
热议问题