Important: Please read the Qt Code of Conduct -

QDesktopWidget::.screenGeometry() from a Thread

  • Hi,

    I am trying to get the exact geometry of every screen in a thread (ran by QThread).
    It seems that QScreen has not the functionality i want. QScreen::availableGeometry() excludes the taskbar from the geometry.

    The alternative is QDesktopWidget::.screenGeometry(screenIndex). However i cannot initiate a QDesktopWidget in my thread.
    ASSERT failure in QWidget: "Widgets must be created in the GUI thread."

    What is the alternative for this to get the info in a thread?

    Kind Regards

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Did you create a QApplication in your main.cpp ?

  • Yes i did.

    And with that clue i figured it out! QApplication::desktop()->screenGeometry(screenIndex); works like a charm.