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] QProcess launching CMD and compiling with it (Windows 8)
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QProcess launching CMD and compiling with it (Windows 8)

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 2.2k 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.
  • P Offline
    P Offline
    petoknm
    wrote on last edited by
    #1

    Hello
    I need my project to compile stuff. So I created a QProcess and started CMD(output is redirected to textEdit)... Now if I then write to it "dir \n" it works great... Everything is displayed as it should(exactly the same way as in a real console)... but if instead of writing "dir \n" I write "g++ (parameters, files...)" All I get in the textEdit is the command "g++ (parameters, files...)" but no other output... I don't know why... Any help is appreciated... Thanks :D

    code:
    @void MainWindow::compileProject(mbedProject *proj,QString *pars){
    QString completePars=*pars+" "+proj->file->fileName()+"\n\r";

    compilerProcess->start("cmd");
    if(!compilerProcess->waitForStarted()){
        qDebug("Error starting cmd!");
    }else{
        compilerProcess->waitForReadyRead(100);
        compilerProcess->waitForFinished(100);
        //compilerProcess->write(("\""+compilerLocation+"/arm-none-eabi-g++.exe\" "+completePars).toUtf8().constData());
        compilerProcess->write("dir \n");
        compilerProcess->closeWriteChannel();
        compilerProcess->waitForBytesWritten(100);
        compilerProcess->waitForReadyRead(100);
        compilerProcess->waitForFinished(100);
        if(compilerProcess->exitCode()==0){
            qDebug("Compilation Successful!");
        }else{
            qDebug("Compilation Failed!");
            // compilation failed
        }
    }
    

    }@
    Picture when writing dir \n
    https://drive.google.com/file/d/0B0bKAstz-Jy6OEVXT3I4VXhKQVk/edit?usp=sharing
    Picture when writing g++...
    https://drive.google.com/file/d/0B0bKAstz-Jy6ZXhPZ0d1TWtTV2M/edit?usp=sharing

    And if I enter the exact same g++... to a CMD opened at that exact location(also with the ""(because of spaces in the path)) I get output... I know that I can't compile .h files it is just what I had at hand...
    And I am redirecting both stdout and stderr(or at least I think so)...
    @connect(compilerProcess,SIGNAL(readyRead()),this,SLOT(updateCompilerOutput()));@

    @void MainWindow::updateCompilerOutput(){
    compilerTextEdit->insertPlainText(compilerProcess->readAll());
    compilerTextEdit->verticalScrollBar()->setValue(compilerTextEdit->verticalScrollBar()->maximum());
    }@

    So what is the difference that causes that dir is ok and g++ is not?

    1 Reply Last reply
    0
    • hskoglundH Offline
      hskoglundH Offline
      hskoglund
      wrote on last edited by
      #2

      Hi maybe a stupid question but haven't you forgotten the \n, I mean instead try:
      @compilerProcess->waitForFinished(100);
      compilerProcess->write(("""+compilerLocation+"/arm-none-eabi-g++.exe""+completePars + "\n").toUtf8().constData());
      @

      1 Reply Last reply
      0
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Qt Champions 2022
        wrote on last edited by
        #3

        I saw your compiler string. It is too big and difficult to experiment. Did you check the command on command line. Copy-paste the same command which is in image you pasted and see it runs. If you are able to run that, you should not have problem here as well

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        1 Reply Last reply
        0
        • P Offline
          P Offline
          petoknm
          wrote on last edited by
          #4

          [quote author="hskoglund" date="1404339237"]Hi maybe a stupid question but haven't you forgotten the \n, I mean instead try:
          @compilerProcess->waitForFinished(100);
          compilerProcess->write(("""+compilerLocation+"/arm-none-eabi-g++.exe""+completePars + "\n").toUtf8().constData());
          @ [/quote]

          I have \n\r in completePars
          @QString completePars=*pars+" "+proj->file->fileName()+"\n\r";@

          1 Reply Last reply
          0
          • P Offline
            P Offline
            petoknm
            wrote on last edited by
            #5

            [quote author="Dheerendra" date="1404358676"]Copy-paste the same command which is in image you pasted and see it runs. If you are able to run that, you should not have problem here as well[/quote]

            https://drive.google.com/file/d/0B0bKAstz-Jy6eTVIQkZNcEVKU2c/edit?usp=sharing

            I copy-pasted it and it did output something...(now its a different file) Could it be possibly because of the missing \n? maybe even if I put it to the string but after the conversion to const char* it disappears or something...?

            1 Reply Last reply
            0
            • P Offline
              P Offline
              petoknm
              wrote on last edited by
              #6

              And if I enter unknown command ("blahblahblah \n") in CMD I get "blahblahblah is unrecognized...blahblahblah"... and in my app I get nothing... well... I get a new line to enter new command(like if the command executed with no output)

              1 Reply Last reply
              0
              • P Offline
                P Offline
                petoknm
                wrote on last edited by
                #7

                And another thing is that if I run this code:
                @QString completePars=proj->file->fileName();
                connect(compilerProcess,SIGNAL(readyReadStandardOutput()),this,SLOT(updateCompilerOutput()));
                connect(compilerProcess,SIGNAL(readyReadStandardError()),this,SLOT(updateCompilerOutput()));
                compilerProcess->execute(compilerLocation+"/arm-none-eabi-g++.exe",QStringList(completePars));@

                the output comes out in the Application output in Qt Creator but it does not come out in the app... and the slot updateCompilerOutput never gets called...why?

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  petoknm
                  wrote on last edited by
                  #8

                  Now its fixed... all I needed was this line of code...
                  @compilerProcess->setProcessChannelMode(QProcess::MergedChannels);@
                  But thanks for your time :D

                  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