Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. PySide: QtSingleApplication?
QtWS25 Last Chance

PySide: QtSingleApplication?

Scheduled Pinned Locked Moved Language Bindings
5 Posts 2 Posters 6.0k 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.
  • T Offline
    T Offline
    ThomasDalla
    wrote on last edited by
    #1

    Hi there,

    I would like to have only one instance of my application, so I found the wonderful QtSingleApplication.
    However, it seems not to be included in PySide so how can we do that with PySide?

    I would like not just to prevent the application to be opened twice or more, but to send the application parameters to the currently running application instead of starting a new one.

    Is it possible?

    1 Reply Last reply
    0
    • R Offline
      R Offline
      renato.filho
      wrote on last edited by
      #2

      QtSingleAppliction is not part of official Qt, then PySide does not create binding for that. I have implemented something like that using a QLocalSocket and QLocalServer.

      The basic idea is:

      // try to connect to your server
      m_socket = QLocalSocket()
      m_socket.connectToServer(qApp.applicationName(), QIODevice.ReadOnly)

      //If this fail is because the app is not running then create the server, then in the next time the connect will work
      m_server = QLocalServer()
      m_server = QLocalServer.listen(qApp.applicationName())

      1 Reply Last reply
      0
      • T Offline
        T Offline
        ThomasDalla
        wrote on last edited by
        #3

        OK, thanks for your help.

        Then I guess I have to use the buffer between the new application (client) and the first launched application (server) to send the new application arguments (using write() and read()), is it?

        I'll try it, thanks again!

        1 Reply Last reply
        0
        • T Offline
          T Offline
          ThomasDalla
          wrote on last edited by
          #4

          It works very well, thank you!

          To go further, it is detected that the application is already currently running, is to possible to put that window on top of the other windows?

          I tried with QMainWindow.activateWindow() but it does not put the window on top of the other windows.
          Is there any way to do it?

          1 Reply Last reply
          0
          • T Offline
            T Offline
            ThomasDalla
            wrote on last edited by
            #5

            I shared this recipe on my blog, with a QSingleApplication class for PySide that allows you to be sure your program will be started only once.
            In addition to start the application only once, we can send the arguments of the later calls of your program to the first (and only remaining) instance.

            Link: http://www.dallagnese.fr/en/computers-it/recette-python-qt4-qsingleapplication-pyside/

            1 Reply Last reply
            0
            • JonBJ JonB referenced this topic on

            • Login

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