Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Compiling a Qt Creator project programmatically
Forum Updated to NodeBB v4.3 + New Features

Compiling a Qt Creator project programmatically

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
2 Posts 2 Posters 748 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.
  • D Offline
    D Offline
    Donald Duck
    wrote on last edited by Donald Duck
    #1

    I'm trying to compile a Qt Creator project programmatically. For this I'm using the following code:

    QTemporaryFile temp;
    ofstream pro(QString(temp.path() + "/project.pro").toLatin1().data());
    pro << "(some stuff)";
    pro.close();
    ofstream cpp(QString(temp.path() + "/main.cpp").toLatin1().data());
    cpp << "(some stuff)"
    cpp.close();
    ofstream user(QString(temp.path() + "/project.pro.user").toLatin1().data());
    user << "(some stuff)";
    user.close();
    QProcess *qmake = new QProcess;
    qmake->start("\"C:\\Qt\\Qt5.7.0_x86\\5.7\\msvc2015\\bin\\qmake.exe\" \"" + temp.path() + "/project.pro\" -r -spec win32-msvc2015");
    QObject::connect(qmake, static_cast<void (QProcess::*)(int)>(&QProcess::finished), [=](int exitCode){
        if(exitCode != 0){
            QMessageBox::critical(window, "Error", "Could not compile. The process qmake.exe exited with code " + QString::number(exitCode));
        }
        else{
            QProcess *jom = new QProcess;
            jom->start("\"C:\\Qt\\Qt5.7.0_x86\\Tools\\QtCreator\\bin\\jom.exe\" \"" + temp.path() + "/build-project-Desktop_Qt_5_7_0_MSVC2015_32bit-Release\"");
            QObject::connect(jom, static_cast<void (QProcess::*)(int)>(&QProcess::finished), [=](int exitCode){
                if(exitCode == 0){
                    QMessageBox::information(window, "Success", "The program was compiled successfully.");
                }
                else{
                    QMessageBox::critical(window, "Error", "Could not compile. The process jom.exe exited with code " + QString::number(exitCode));
                }
            });
        }
    });
    

    The problem is that the program doesn't compile because jom.exe exits with code 2. But when I open the project in Qt Creator and compile it manually, it works just fine. What am I doing wrong?

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi! Two guesses: Wrong working directory, missing environment variables.

      1 Reply Last reply
      1

      • Login

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