Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. REGEX in QString isnt passed correct to QProcess
Forum Updated to NodeBB v4.3 + New Features

REGEX in QString isnt passed correct to QProcess

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.9k Views 1 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.
  • M Offline
    M Offline
    mr_maddog
    wrote on last edited by
    #1

    Hi,
    with the code below i load a file named fileName into a perlscript.
    With the regex (!/^$/) i get rid of all lines that starts with a $ .
    the rest is put into a variable alllines.
    after that the program is passed into a QProcess and all the output directed to QListView.

    I get the following error

    Fehler:unknown escape sequence '$'

    my idea is that the regex !/^$/ is the problem.

    @
    oid EngMountStiff::on_commandLinkButton_clicked()
    {

    QString aScript =    "$file = \""+fileName+"\";"
            "print $file;"
                         " open(PCH, $file);  # Open the file "
                         " while (<PCH>) {                               "
                        "    if (!/^\$/)                                "
                        "    {                                          "
                         "        push(@alllines,$_);                    "
                        "    }                                          "
                         "}                                              "
                        "close(PCH);   # Close the file        "
    "print @alllines;";
    
    //start perlscript
    QProcess perl;
    QString perlscript = "/usr/bin/perl";
    
    
    
    
    perl.start(perlscript);
    perl.write(aScript.toUtf8());
    perl.closeWriteChannel();
    perl.waitForFinished(-1);
    perl.setProcessChannelMode(QProcess::MergedChannels);
    QString p_stdout = perl.readAllStandardOutput();
    QString p_stderr = perl.readAllStandardError();
    
    //stream in processwindow
     ui->output->setText(p_stderr);
     ui->output->setText(p_stdout);
    

    @

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Escape it properly, then:
      @
      " if (!/^\$/)"
      @

      (Z(:^

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mr_maddog
        wrote on last edited by
        #3

        I am sorry but than the regex isnt working correct.
        But u are rigth the programm is running.

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Try with simpler scripts (a hello world or something) to see if Perl is really working well from within QProcess.

          (Z(:^

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mr_maddog
            wrote on last edited by
            #5

            Allready done. Simple hello world is working and only printing the file fileName is also ok.
            Do you have an idea how to ouput the resulting qstring (aScript), after it is processed, so i can see how the \$ is translated?

            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