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. QPushButton that run external app

QPushButton that run external app

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 1.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.
  • A Offline
    A Offline
    AZimmerer
    wrote on last edited by
    #1

    Hi,

    I have a quick question. I created a QPushButton called extapp_btn.
    Now I want to connect it with an external app. In my example bellow
    I push the button and notepad.exe should start.

    How can I connect them?

    -example code ----------------------------------

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QWebView>
    #include <QUrl>
    #include <QPushButton>
    #include <QProcess>

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    ui->webView->load(QUrl("http://localhost"));

    QPushButton * extapp_btn = new QPushButton(this);
    extapp_btn->setGeometry(540,440,93,27);
    extapp_btn->setText("External App");
    

    QProcess *proc = new QProcess (this);
    // proc->start ("notepad.exe");

    QObject::connect(extapp_btn_btn,SIGNAL(clicked()),qApp,SLOT( START EXTERNAL APP ));

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

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

      Well just put the QProcess code into
      START EXTERNAL APP slot ?
      Or do u ask how to make slot ?
      Also you say that qApp has the slot.
      Dont you mean "this" for mainwidow ?

      1 Reply Last reply
      2
      • A Offline
        A Offline
        AZimmerer
        wrote on last edited by AZimmerer
        #3

        Thanks for helping me out. I am complete noob. So what I want to do is. If I click on the button „extapp_btn“ notpad should start. How do I have to modify my code?

        mrjjM 1 Reply Last reply
        0
        • A AZimmerer

          Thanks for helping me out. I am complete noob. So what I want to do is. If I click on the button „extapp_btn“ notpad should start. How do I have to modify my code?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @AZimmerer

          You should read this
          http://doc.qt.io/qt-5/signalsandslots.html

          Anyway, you need to add slot to mainwin.

          class MainWindow : public QMainWindow
          {
          Q_OBJECT
          ....
          private slots: // this you might to write too
          void StartApp(); // this is the slot. a normal function
          ..

          and in mainwindow.cpp
          void MainWindow::StartApp() {
          QProcess::startDetached("notepad.exe");
          }

          then
          QObject::connect(extapp_btn_btn,SIGNAL(clicked()),this,SLOT( StartApp()));

          1 Reply Last reply
          9
          • A Offline
            A Offline
            AZimmerer
            wrote on last edited by
            #5

            thank you very much. worked like a charm :D

            1 Reply Last reply
            1
            • Gojir4G Offline
              Gojir4G Offline
              Gojir4
              wrote on last edited by
              #6

              Hi,

              You can even give the file to be opened in arguments :

              QProcess::startDetached("notepad++",  QStringList() << "path/to/the/file.txt");
              
              A 1 Reply Last reply
              1
              • Gojir4G Gojir4

                Hi,

                You can even give the file to be opened in arguments :

                QProcess::startDetached("notepad++",  QStringList() << "path/to/the/file.txt");
                
                A Offline
                A Offline
                AZimmerer
                wrote on last edited by
                #7

                @Gojir4 said in QPushButton that run external app:

                Hi,

                You can even give the file to be opened in arguments :

                QProcess::startDetached("notepad++",  QStringList() << "path/to/the/file.txt");
                

                Thanks for the help. much appreciated

                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