Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Firefox start when close

    General and Desktop
    c++ qprocess
    3
    5
    1525
    Loading More Posts
    • 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
      mateczek last edited by 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 1 Reply Last reply Reply Quote 0
      • ?
        A Former User last edited by A Former User

        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 Reply Quote 0
        • David.G
          David.G last edited by

          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 Reply Quote 0
          • M
            mateczek @mateczek last edited by mateczek

            This post is deleted!
            1 Reply Last reply Reply Quote 0
            • M
              mateczek last edited by mateczek

              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 Reply Quote 0
              • First post
                Last post