Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. How to pass reguaklr expression - from string list ?
Forum Updated to NodeBB v4.3 + New Features

How to pass reguaklr expression - from string list ?

Scheduled Pinned Locked Moved Unsolved C++ Gurus
3 Posts 2 Posters 513 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by
    #1

    Another C++ code under construction and I need advise.

    cursor = document->find(str);  will accept regular expression , but I am passing plain QString. That is no go. 
    

    I like to keep that QString in QStringList , but I do not know how and where to build regular expression - in foreach loop. .

    I did try - replacing the QString , but that is wrong - it breaks the QStringList .

    QRegularExpression re( [0-F]{2}[:]){5}[0-F]{2}", "([0-F]{2}[:] ) ;

        QStringList BT_Setup[16] = {{  "controller","Powered: yes","Discoverable: no","Pairable: no","Discovering: no",
                                     "([0-F]{2}[:]){5}[0-F]{2}", "([0-F]{2}[:])"  },
                                     {  "contoller", "Remote", "Control"},
                                     {  "contoller", "Remote", "Control"}
        };
        QTextDocument * document = ui->textEdit_35->document();
        QTextCursor cursor = ui->textEdit_35->textCursor();
        QTextCharFormat fmt = cursor.charFormat();
        fmt.setBackground(Qt::green);
    
        foreach(str, BT_Setup[0])
        { // foreach block
            qDebug() << "DEBUG POINT "  << QString::number(__LINE__);
            qDebug() << "DEBUG POINT "  << str;
    
          convert str  to regular expression here ?? 
    
            cursor = document->find(str);
            if(cursor.isNull())
            {
             qDebug() << "FAILED DEBUG POINT "  << QString::number(__LINE__);
            qDebug() << "DEBUG POINT "  << str;
            }
           cursor.setCharFormat(fmt);
        }// foreach block
    
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Since QRegularExpression has a constructor that takes a QString ,
      cant you just say

      QRegularExpression exp(str);
      cursor = document->find( exp);
      
      A 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi
        Since QRegularExpression has a constructor that takes a QString ,
        cant you just say

        QRegularExpression exp(str);
        cursor = document->find( exp);
        
        A Offline
        A Offline
        Anonymous_Banned275
        wrote on last edited by
        #3

        @mrjj Perfect - I just cannot think as a compiler - plain string as regular expression....
        SOLVED

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved