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. ScreenAdded signal does not work
Forum Updated to NodeBB v4.3 + New Features

ScreenAdded signal does not work

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 5 Posters 1.4k Views 2 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.
  • S Offline
    S Offline
    Siset
    wrote on last edited by Siset
    #1

    Hello everyone,

    I found this topic that has not been answered yet: QGuiApplication::screenAdded signal never emitted

    My question is simpler: How to correctly use screenAdded signal? I do not receive such signal in my class.

    I am using QT 5.14.1 on windows (specifically on MSVC 2017) and the important code is as follows:

    The .h:

    class QtGuiMyClass : public QWidget
    {
    Q_OBJECT
    
    public:
    	QtGuiMyClass (QGuiApplication * qga, QWidget *parent = Q_NULLPTR);
    private:
    	QGuiApplication * m_qga;
    private slots:
    	
    	void screenChange(QScreen *screen);
    };
    

    The .cpp

    QtGuiMyClass ::QtGuiMyClass (QGuiApplication * qga,QWidget *parent)
    	: QWidget(parent)
    	, ui(new Ui::QtGuiMyClass )
    {
            ui->setupUi(this);
    	m_qga = qga;
            connect(m_qga, &QGuiApplication::screenAdded, this, &QtGuiMyClass ::screenChange);
    }
    void QtGuiMyClass ::screenChange(QScreen *screen) {
    	std::cout << "screen changed!" << std::endl; //<-This is never executed 
    }
    

    The main.cpp

            QApplication a(argc, argv);	
    	QtGuiMyClass w(&a);
    	w.show();
    	return a.exec();
    

    Thank you in advanced,

    Pl45m4P 1 Reply Last reply
    0
    • S Siset

      Hello everyone,

      I found this topic that has not been answered yet: QGuiApplication::screenAdded signal never emitted

      My question is simpler: How to correctly use screenAdded signal? I do not receive such signal in my class.

      I am using QT 5.14.1 on windows (specifically on MSVC 2017) and the important code is as follows:

      The .h:

      class QtGuiMyClass : public QWidget
      {
      Q_OBJECT
      
      public:
      	QtGuiMyClass (QGuiApplication * qga, QWidget *parent = Q_NULLPTR);
      private:
      	QGuiApplication * m_qga;
      private slots:
      	
      	void screenChange(QScreen *screen);
      };
      

      The .cpp

      QtGuiMyClass ::QtGuiMyClass (QGuiApplication * qga,QWidget *parent)
      	: QWidget(parent)
      	, ui(new Ui::QtGuiMyClass )
      {
              ui->setupUi(this);
      	m_qga = qga;
              connect(m_qga, &QGuiApplication::screenAdded, this, &QtGuiMyClass ::screenChange);
      }
      void QtGuiMyClass ::screenChange(QScreen *screen) {
      	std::cout << "screen changed!" << std::endl; //<-This is never executed 
      }
      

      The main.cpp

              QApplication a(argc, argv);	
      	QtGuiMyClass w(&a);
      	w.show();
      	return a.exec();
      

      Thank you in advanced,

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @Siset

      You need to add a screen to your system in order to emit this signal.

      https://doc.qt.io/qt-5/qguiapplication.html#screenAdded


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Siset
        wrote on last edited by
        #3

        @Pl45m4
        Thanks for the answer. Do you mean that I need to declare a new Screen? Then this signal is emitted? I understood that this signal would fire everytime a new screen is added to the system (connected via HDMI for example or turned on).
        Is that not the case?

        Thanks,

        Pl45m4P 1 Reply Last reply
        0
        • S Siset

          @Pl45m4
          Thanks for the answer. Do you mean that I need to declare a new Screen? Then this signal is emitted? I understood that this signal would fire everytime a new screen is added to the system (connected via HDMI for example or turned on).
          Is that not the case?

          Thanks,

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by
          #4

          @Siset

          I was expecting that too. Isnt this working?
          Try to change the display settings on your OS while running your app (Screen modes: clone, extend, change primary screen, etc.)

          You could also try this example to check if Qt or your app knows about your second screen (when plugged-in or activated by OS' window manager)
          Screen settings example


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Siset
            wrote on last edited by
            #5

            @Pl45m4

            Thank you for your time.

            No, it does not fire when I change the display settings. But yes, once turned on all the screens()[1] functions work (except for the serial number,name,model...). The problem is that the signal seems to never reach the screenChange (i do not even know if it is emitted in the first place).

            Any other suggestion?

            Thanks,

            1 Reply Last reply
            0
            • S Offline
              S Offline
              soyoo
              wrote on last edited by
              #6

              @Siset
              According to my test, QGuiApplication always keep a primary screen, and QGuiApplication::screens() keep 1 when there is not a screen plug to your machine; you must plug a screen to another HMI port, then screenAdded signal will be fired, QGuiApplication::screens() will be increase to 2.

              S 2 Replies Last reply
              3
              • S soyoo

                @Siset
                According to my test, QGuiApplication always keep a primary screen, and QGuiApplication::screens() keep 1 when there is not a screen plug to your machine; you must plug a screen to another HMI port, then screenAdded signal will be fired, QGuiApplication::screens() will be increase to 2.

                S Offline
                S Offline
                Siset
                wrote on last edited by
                #7
                This post is deleted!
                1 Reply Last reply
                0
                • S soyoo

                  @Siset
                  According to my test, QGuiApplication always keep a primary screen, and QGuiApplication::screens() keep 1 when there is not a screen plug to your machine; you must plug a screen to another HMI port, then screenAdded signal will be fired, QGuiApplication::screens() will be increase to 2.

                  S Offline
                  S Offline
                  Siset
                  wrote on last edited by
                  #8

                  @soyoo
                  Thank you very much!

                  I've just found the problem. If I turn off/on the screen it does not detect anything, in fact, with the screen switched off qApp->screens().size() is 2!! This happens in a TV, in my monitor screen this behaviour does not appear.

                  Thanks,

                  W 1 Reply Last reply
                  0
                  • S Siset

                    @soyoo
                    Thank you very much!

                    I've just found the problem. If I turn off/on the screen it does not detect anything, in fact, with the screen switched off qApp->screens().size() is 2!! This happens in a TV, in my monitor screen this behaviour does not appear.

                    Thanks,

                    W Offline
                    W Offline
                    wrosecrans
                    wrote on last edited by
                    #9

                    Yup, as long as the underlying system thinks the number of screens is the same, the signal won't fire, even if the user might expect it to. A turned off monitor can still be detected. Config can be hard-coded instead of set to detect changes. A new monitor can be captured by the driver as part of an existing "virtual" screen that just got bigger, instead of an actual new screen.

                    My personal computer has two screens, and when I forget to turn one on before I boot, it still detects it just fine so when I turn it on, that desktop is already there, the system doesn't have to blip and reconfigure like when I plug my laptop into a TV. It can be counterintuitive.

                    1 Reply Last reply
                    2
                    • guardG Offline
                      guardG Offline
                      guard
                      wrote on last edited by
                      #10

                      Hello, I also found that similar to the number of screen access changes, screenAdded signal did not receive, how do you solve it, thank you

                      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