Qt4 Qt5:如何确定屏幕像素格式?

Qt4 Qt5:如何确定屏幕像素格式?,qt4,qt5,embedded-linux,Qt4,Qt5,Embedded Linux,我正在将一个应用程序从嵌入式Qt4移植到Qt5。因此,我需要以下表达式的等价项: QScreen::instance()->pixelFormat() QScreen不再具有静态instance()功能,也不提供pixelFormat() 所以基本上我需要确定屏幕的像素格式。我需要它作为QImage的构造函数的第二个参数,如果以下解决方法不能满足您的需要,请使用: QPlatformScreen*QScreen::handle()常量 解决方法: 也许您可以使用QScreen::dept

我正在将一个应用程序从嵌入式Qt4移植到Qt5。因此,我需要以下表达式的等价项:

QScreen::instance()->pixelFormat()
QScreen不再具有静态
instance()
功能,也不提供
pixelFormat()


所以基本上我需要确定屏幕的像素格式。我需要它作为
QImage

的构造函数的第二个参数,如果以下解决方法不能满足您的需要,请使用:
QPlatformScreen*QScreen::handle()常量

解决方法:
也许您可以使用
QScreen::depth
,然后将其值与适当的
QImage::format
匹配:

QImage::Format ConvertDepthToFormat(int depth)
{
   QImage::Format format = QImage::Format_Invalid;
   switch (depth)
   {
      case 16:
         format = QImage::Format_RGB16;
         break;

      case 32:
         format = QImage::Format_RGB32;
         break; 
   }
   return format;
}

int main(int argc, char *argv[])
{
    QGuiApplication a(argc, argv);

    int depth = 0;
    foreach (QScreen *screen, QGuiApplication::screens())
    {
       depth = screen->depth();
       qDebug() << "Depth:" << depth << "-bits";
       QImage::Format format = ConvertDepthToFormat(depth);
    }
    return a.exec(); 
}
QImage::Format ConvertDepthToFormat(int-depth)
{
QImage::Format Format=QImage::Format_无效;
开关(深度)
{
案例16:
format=QImage::format_RGB16;
打破
案例32:
format=QImage::format_RGB32;
打破
}
返回格式;
}
int main(int argc,char*argv[])
{
QGUI应用程序a(argc、argv);
int深度=0;
foreach(QScreen*screen,qgui应用程序::screens())
{
深度=屏幕->深度();

qDebug()可能通过使用一点私有API(QPA,
QPlatformScreen
):
QScreen::handle()
然后
screenFormat()
。您需要
QT+=guiprivate
。顺便说一句,您可以通过
qgui应用程序
primaryScreen()
screen()
)获得屏幕列表。