#include#include #include int main(int argc, char *argv[]) { QApplication app(argc, argv); QDesktopWidget *desktop = QApplication::desktop(); int primaryScreenIndex = desktop->primaryScreen(); qDebug() << "Primary Screen Index:" << primaryScreenIndex; return app.exec(); }
#includeIn this example, we are using the screenGeometry() method to get the geometry (size and position) of the primary screen and printing it to the console using qDebug(). Package/Library: Qt (QtWidgets)#include #include int main(int argc, char *argv[]) { QApplication app(argc, argv); QDesktopWidget *desktop = QApplication::desktop(); QRect primaryScreenGeometry = desktop->screenGeometry(desktop->primaryScreen()); qDebug() << "Primary Screen Geometry:" << primaryScreenGeometry; return app.exec(); }