Firefox start when close



  • 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


  • Moderators

    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.



  • 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)



  • This post is deleted!


  • 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);
        }
    }
    
    
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.