when i use "QScreen *screen = QGuiApplication::primaryScreen()" ,i get nullptr
-
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.
-
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.
-
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.
@_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 requiereQT += gui
in the pro file.so my suggestion, change QCoreApplication to QGuiApplication.
-
@_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 requiereQT += gui
in the pro file.so my suggestion, change QCoreApplication to QGuiApplication.