Qt Forum

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

    Unsolved when i use "QScreen *screen = QGuiApplication::primaryScreen()" ,i get nullptr

    General and Desktop
    3
    5
    1558
    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.
    • _
      _hunter last edited by

      include<iostream>
      int main(int argc, char *argv[])
      {
      QCoreApplication a(argc, argv);

      QScreen *screen = QGuiApplication::primaryScreen();
      
      QString filePathName = "full-";
      
      filePathName += QDateTime::currentDateTime().toString("yyyy-MM-dd hh-mm-ss-zzz");
      
      filePathName += ".jpg";
      if(screen == nullptr)
      {
          std::cout<<"get nothing"<<std::endl;
      }
      

      }

      i always get a nullptr ,i do not know why.anyone can help me.

      _ J.Hilk 2 Replies Last reply Reply Quote 0
      • _
        _hunter @_hunter last edited by

        @_hunter and the os is ubuntu16.04

        1 Reply Last reply Reply Quote 0
        • J.Hilk
          J.Hilk Moderators @_hunter last edited by

          @_hunter said in when i use "QScreen *screen = QGuiApplication::primaryScreen()" ,i get nullptr:

          QCoreApplication

          I wild guess on my side:
          QCoreApplication is for applications without GUI, QGuiApplication::primaryScreen is static function, but it would at least requiere QT += gui in the pro file.

          so my suggestion, change QCoreApplication to QGuiApplication.

          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct

          Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          _ 1 Reply Last reply Reply Quote 3
          • _
            _hunter @J.Hilk last edited by

            @J.Hilk thank you,this help me a lot

            aha_1980 1 Reply Last reply Reply Quote 1
            • aha_1980
              aha_1980 Lifetime Qt Champion @_hunter last edited by

              @_hunter If your problem is solved, please mark this topic as SOLVED too.

              Thanks.

              Qt has to stay free or it will die.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post