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
Qt 6.11 is out! See what's new in the release blog

Firefox start when close

Scheduled Pinned Locked Moved General and Desktop
c++qprocess
5 Posts 3 Posters 2.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.
  • M Offline
    M Offline
    mateczek
    wrote on 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
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on 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
      • David.GD Offline
        David.GD Offline
        David.G
        wrote on 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

          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 last edited by mateczek
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • M Offline
            M Offline
            mateczek
            wrote on 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

            • Login

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