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. [Solved]QT widget doesnt work due to open a file in a QProcess

[Solved]QT widget doesnt work due to open a file in a QProcess

Scheduled Pinned Locked Moved General and Desktop
13 Posts 4 Posters 4.4k 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 all,
    i have here a nice problem.
    I wrote a small gui for starting a perlscript. This script prints out the stuff which is defined in my gui.After that i write a file with the variables and start thru a QProcess a perlscript to process the data.

    The problem is, that the perl script isnt working. If i comment out the open file, in the perlscript everything is ok.

    Thanks for some hints..

    Greetz

    Below see my files.

    @mainwindow.ccp
    void MainWindow::on_commandLinkButton_clicked()
    {
    //input variables
    QString Variant = ui->inputVariant->text();
    QString Load = ui->inputLoad->text();

    //write file
    QFile inputfile("/fs1/PerlQt/QtCreator/test/variables.inp");
    inputfile.open(QFile::WriteOnly|QFile::Truncate|QFile::Text);
    QTextStream str(&inputfile);
    QStringList list;
    list << Variant << Load ;
    foreach(const QString &s, list)
    {
    str << s << endl;
    }

    //start perlscript
    QProcess perl;
    perl.start("./fs1/PerlQt/QtCreator/test/test.pl"&#41;;
    perl.waitForFinished(-1&#41;;
    
    QString p_stdout = perl.readAllStandardOutput(&#41;;
    QString p_stderr = perl.readAllStandardError();
    
    //output in textwindow
    ui->output->setText(p_stderr);
    ui->output->setText(p_stdout);
    

    }

    test.pl
    #!/usr/bin/perl

    sub print_var()
    {
    print "Name \n\n"; #print name
    print "=> $files[0] \n"; #print the first entry in array files
    }
    open incl, 'variables.inp' or die "Datei nicht gefunden $!"; # open the file variables.inp
    @files = <incl>; #read in file and fill a array @files
    close(incl); #close file
    print "agghagh \n\n"; #print stupid stuff
    print_var(); #print the stuff which is in sub print_var@

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Hmm, Your code is almost unreadable! Place it in the code box please!!

      Greetz, Jeroen

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        At first sight, you try to open a file with perl that is still opened by QFile (the data might be still in a buffer and not yet on the disk).

        What happens if you close inputFile before calling your perl script ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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

          tried and the same. no output.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Just in case, did you saw that your inputFile is "/fs1/PerlQt/QtCreator/test/variables.inp" and your script is "./fs1/PerlQt/QtCreator/test/test.pl" <= There's a dot in front here.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by
              #6

              By default QProcess is started with a working directory of the calling process. Since you have a relative path in your perl script it is looking for input file in the directory of your executable, not where the script file is. Use QProcess::setWorkingDirectory() to change that.

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

                @SGaist: ./ is for start the script here. This is normal linux stuff, but thanks for the hint.
                @krzysztof: i catch stderr, so ishould get an error,file not found and the perlscript should print the first aggah and then i shold get errormessage, because the file is processed after the print command. Setting the file to an absolut path didnt work as well.

                but anyway thanks to u guys.
                Hope we will find the error, any others thoughts....

                1 Reply Last reply
                0
                • Chris KawaC Offline
                  Chris KawaC Offline
                  Chris Kawa
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Ok, this might be stupid because I know little about linux and how QProcess behaves there, but maybe this would work?
                  @
                  perl.start("perl ./fs1/PerlQt/QtCreator/test/test.pl");
                  @

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

                    as well no output.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      That's why i suggested you to double check the use of "./" since your inputFile path is an absolute path but your perl script path is relative. That might be the culprit.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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

                        Hi,

                        i changed everything to absolute paths and started the perl with

                        perl.start("perl /fs1/PerlQt/QtCreator/test/test.pl");

                        Thats not the problem. there is still no output.

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          Did you check the working directory of your perl script ?
                          Besides that, make it print the content of the current directory, that might give your some clues

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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

                            For all whoo are interessted in.
                            The problem was the following code in perl, which wasnt correctly compiled due QT.

                            @open incl, 'variables.inp' or die "Datei nicht gefunden $!"; # open the file variables.inp@

                            This line open a file and if the file not exists the applikation die and print file not found.
                            I found out, that without the booleen or die everything is ok and worked.

                            Thanks for all your post and the help.

                            Greetz

                            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