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. Firefox start when close
Forum Update on Monday, May 27th 2025

Firefox start when close

Scheduled Pinned Locked Moved General and Desktop
c++qprocess
5 Posts 3 Posters 1.9k Views
  • 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
    mateczek
    wrote on 27 Jan 2016, 19:43 last edited by mateczek
    #1

    Firefox start when close - console application (Linux)

    header file

    #ifndef MAPP_H
    #define MAPP_H
    #include<QCoreApplication>
    #include<QProcess>
    
    class mApp : public QCoreApplication
    {
        Q_OBJECT
        QProcess* fproc;
        const QString progName{"/usr/bin/firefox"};
        const QStringList wwwSite{{"-new-window"},{"localhost"}};
    public:
        mApp(int argc, char *argv[]);
        ~mApp();
    
    signals:
    
    public slots:
       void ffoxClose(int a);
    };
    
    #endif // MAPP_H
    
    

    source file

    #include "mapp.h"
    #include<QDebug>
    
    mApp::mApp(int argc, char *argv[]):QCoreApplication(argc, argv)
    {
       fproc=new QProcess(this);
       fproc->start(progName,wwwSite);
       connect(fproc,SIGNAL(finished(int)),this, SLOT(ffoxClose(int)));
    }
    
    mApp::~mApp()
    {
      fproc->close();
      fproc->destroyed();
    
    }
    
    void mApp::ffoxClose(int a) //gdy aplikacja się skończy to odpalam ponownie
    {
       qDebug()<<"1";
       fproc->start(progName,wwwSite);
    }
    

    I want to start firefox again when the firefox is closed.
    my solution is wrong, because sometimes generates multiple browser windows. (sometimes work correctly )
    My program sometimes, in an endless loop generates new Firefox window!!!
    where is wrong??

    thank You for watching

    M 1 Reply Last reply 28 Jan 2016, 11:35
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on 27 Jan 2016, 20:33 last edited by A Former User
      #2

      Your code is correct. The problem here is that firefox always only runs a single process. Everytime you call /usr/bin/firefox it checks if there is already a running instance and if this is true it just tells it to open another window and then returns.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        David.G
        wrote on 27 Jan 2016, 20:33 last edited by
        #3

        Perhaps a tiny bit unrelated to your question but have you considered using QDesktopServices instead of opening a whole process? The helper class will open the default browser the user uses, most of the time using the correct window. (at least in my experience)

        1 Reply Last reply
        0
        • M mateczek
          27 Jan 2016, 19:43

          Firefox start when close - console application (Linux)

          header file

          #ifndef MAPP_H
          #define MAPP_H
          #include<QCoreApplication>
          #include<QProcess>
          
          class mApp : public QCoreApplication
          {
              Q_OBJECT
              QProcess* fproc;
              const QString progName{"/usr/bin/firefox"};
              const QStringList wwwSite{{"-new-window"},{"localhost"}};
          public:
              mApp(int argc, char *argv[]);
              ~mApp();
          
          signals:
          
          public slots:
             void ffoxClose(int a);
          };
          
          #endif // MAPP_H
          
          

          source file

          #include "mapp.h"
          #include<QDebug>
          
          mApp::mApp(int argc, char *argv[]):QCoreApplication(argc, argv)
          {
             fproc=new QProcess(this);
             fproc->start(progName,wwwSite);
             connect(fproc,SIGNAL(finished(int)),this, SLOT(ffoxClose(int)));
          }
          
          mApp::~mApp()
          {
            fproc->close();
            fproc->destroyed();
          
          }
          
          void mApp::ffoxClose(int a) //gdy aplikacja się skończy to odpalam ponownie
          {
             qDebug()<<"1";
             fproc->start(progName,wwwSite);
          }
          

          I want to start firefox again when the firefox is closed.
          my solution is wrong, because sometimes generates multiple browser windows. (sometimes work correctly )
          My program sometimes, in an endless loop generates new Firefox window!!!
          where is wrong??

          thank You for watching

          M Offline
          M Offline
          mateczek
          wrote on 28 Jan 2016, 11:35 last edited by mateczek
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • M Offline
            M Offline
            mateczek
            wrote on 31 Jan 2016, 21:57 last edited by mateczek
            #5

            thank you for ALL !!!
            I present final solution
            header

            #ifndef MAPP_H
            #define MAPP_H
            #include<QCoreApplication>
            #include<QProcess>
            #include<QFile>
            
            class mApp : public QCoreApplication
            {
                Q_OBJECT
                QProcess* fproc;
                const QString progName{"/usr/bin/firefox"};
                const QStringList wwwSite{{"localhost"},{"-P marek"},{"-no-remote"}};
                const QStringList killffox{{"firefox"}};
            public:
                mApp(int argc, char *argv[]);
                ~mApp();
            
            signals:
            
            public slots:
               void ffoxClose(int a);
            };
            
            #endif // MAPP_H
            
            

            souce

            #include "mapp.h"
            #include<QFileInfo>
            
            mApp::mApp(int argc, char *argv[]):QCoreApplication(argc, argv)
            {
               fproc=new QProcess(this);
               QFileInfo lock("/home/tygrysy/.mozilla/firefox/marek/lock"); //file exist when firefox is run
               if (lock.isSymLink()){
                    fproc->start("killall",killffox);
                    fproc->waitForFinished();
               }
               fproc->start(progName,wwwSite);
               connect(fproc,SIGNAL(finished(int)),this, SLOT(ffoxClose(int)));
            
            }
            
            mApp::~mApp()
            {
              fproc->close();
              fproc->destroyed();
            
            }
            
            void mApp::ffoxClose(int a) //gdy aplikacja się skończy to odpalam ponownie
            {
            
                QFileInfo lock("/home/tygrysy/.mozilla/firefox/marek/lock"); // file exist when firefox run :P
                if (!lock.isSymLink()){
                     fproc->start(progName,wwwSite);
                }
            }
            
            
            
            1 Reply Last reply
            0

            4/5

            28 Jan 2016, 11:35

            • Login

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