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. Tryin to run an executable from a click of a pushbutton
Forum Updated to NodeBB v4.3 + New Features

Tryin to run an executable from a click of a pushbutton

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

    Hi there, I am new to QT Creator, I am currently trying to run an executable file with a click of a button, what keeps happening is that it runs the executable but only on the application output tab and not independently outside of QT, how do I make sure that it runs by itself?

    void MainWindow::on_pushButton_3_clicked()
    {

    QString botDirectory = QDir::currentPath() + "/BOTS";
    QString botFolderPath = botDirectory + "/" + selectedBot;
    QDir botDir(botFolderPath);
    QStringList exeFiles = botDir.entryList(QStringList() << "*.exe", QDir::Files);
    
    if (exeFiles.isEmpty()) {
        QMessageBox::critical(this, tr("Error"), tr("No executable found in the bot folder."));
        return;
    }
    
    QString botExecutablePath = botFolderPath + "/" + exeFiles.first();
    QString machineIDPath = botFolderPath + "/MachineID.txt";
    
    // Debug: Print paths
    qDebug() << "Bot Folder Path: " << botFolderPath;
    qDebug() << "Bot Executable Path: " << botExecutablePath;
    qDebug() << "MachineID Path: " << machineIDPath;
    
    if (!QFile::exists(machineIDPath)) {
        qDebug() << "MachineID.txt file does not exist.";
        QMessageBox::critical(this, tr("Error"), tr("MachineID.txt file not found in the bot folder."));
        return;
    }
    
    qDebug() << "Attempting to start bot executable:" << botExecutablePath;
    
    // Start the process detached
    qint64 pid;
    bool success = QProcess::startDetached(botExecutablePath, QStringList(), botFolderPath, &pid);
    
    if (!success) {
        // Handle error if the process did not start
        QMessageBox::critical(this, tr("Error"), tr("Failed to start the executable."));
    } else {
        // Handle success if the process started
        qDebug() << "Executable started:" << botExecutablePath;
    }
    

    }

    ^ This is my code, the executable itself runs properly from File Explorer, and the paths are configured properly all I need is for it to run on its own, any help?

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

      Hi and welcome to devnet,

      What exactly are you seeing ?
      Is it a command line application ?
      What do you mean by "only on the application output" ?

      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

      • Login

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