如果我在台式机(Linux或Windows)上使用应用程序时在应用程序中使用qApp->primaryScreen()->availableGeometry();时,请获取可用屏幕的大小,这对我来说很重要,因为应用程序每个元素的大小都是根据屏幕上可用的高度和宽度来计算的,但是在ADV上运行时,始终返回0x0,这妨碍了正确的应用程序功能。
如果我尝试在物理设备中进行部署,则调试器和应用程序甚至无法启动。
在完整的日志中,我得到的是:

Debugging starts
D/dalvikvm( 4630): Not late-enabling CheckJNI (already on)
I/dalvikvm( 4630): Zip is good, but no classes.dex inside, and no valid .odex file in the same directory
I/dalvikvm( 4630): Zip is good, but no classes.dex inside, and no valid .odex file in the same directory
I/dalvikvm( 4630): Zip is good, but no classes.dex inside, and no valid .odex file in the same directory
I/dalvikvm( 4630): Zip is good, but no classes.dex inside, and no valid .odex file in the same directory
D/dalvikvm( 4630): Trying to load lib /data/local/tmp/qt/lib/libgnustl_shared.so 0xb2d01db8
D/dalvikvm( 4630): Added shared lib /data/local/tmp/qt/lib/libgnustl_shared.so 0xb2d01db8
D/dalvikvm( 4630): No JNI_OnLoad found in /data/local/tmp/qt/lib/libgnustl_shared.so 0xb2d01db8, skipping init
D/dalvikvm( 4630): Trying to load lib /data/local/tmp/qt/lib/libQt5Core.so 0xb2d01db8
D/dalvikvm( 4630): Added shared lib /data/local/tmp/qt/lib/libQt5Core.so 0xb2d01db8
D/dalvikvm( 4630): Trying to load lib /data/local/tmp/qt/lib/libQt5Gui.so 0xb2d01db8
D/dalvikvm( 4630): Added shared lib /data/local/tmp/qt/lib/libQt5Gui.so 0xb2d01db8
D/dalvikvm( 4630): No JNI_OnLoad found in /data/local/tmp/qt/lib/libQt5Gui.so 0xb2d01db8, skipping init
D/dalvikvm( 4630): Trying to load lib /data/local/tmp/qt/lib/libQt5Network.so 0xb2d01db8
D/dalvikvm( 4630): Added shared lib /data/local/tmp/qt/lib/libQt5Network.so 0xb2d01db8
D/dalvikvm( 4630): No JNI_OnLoad found in /data/local/tmp/qt/lib/libQt5Network.so 0xb2d01db8, skipping init
D/dalvikvm( 4630): Trying to load lib /data/local/tmp/qt/lib/libQt5Qml.so 0xb2d01db8
D/dalvikvm( 4630): Added shared lib /data/local/tmp/qt/lib/libQt5Qml.so 0xb2d01db8
D/dalvikvm( 4630): No JNI_OnLoad found in /data/local/tmp/qt/lib/libQt5Qml.so 0xb2d01db8, skipping init
D/dalvikvm( 4630): Trying to load lib /data/local/tmp/qt/lib/libQt5Quick.so 0xb2d01db8
D/dalvikvm( 4630): Added shared lib /data/local/tmp/qt/lib/libQt5Quick.so 0xb2d01db8
D/dalvikvm( 4630): No JNI_OnLoad found in /data/local/tmp/qt/lib/libQt5Quick.so 0xb2d01db8, skipping init
D/dalvikvm( 4630): Trying to load lib /data/local/tmp/qt/lib/libQt5Widgets.so 0xb2d01db8
D/dalvikvm( 4630): Added shared lib /data/local/tmp/qt/lib/libQt5Widgets.so 0xb2d01db8
D/dalvikvm( 4630): No JNI_OnLoad found in /data/local/tmp/qt/lib/libQt5Widgets.so 0xb2d01db8, skipping init
D/dalvikvm( 4630): Trying to load lib /data/local/tmp/qt/lib/libQt5Sql.so 0xb2d01db8
D/dalvikvm( 4630): Added shared lib /data/local/tmp/qt/lib/libQt5Sql.so 0xb2d01db8
D/dalvikvm( 4630): No JNI_OnLoad found in /data/local/tmp/qt/lib/libQt5Sql.so 0xb2d01db8, skipping init
D/dalvikvm( 4630): Trying to load lib /data/local/tmp/qt/lib/libQt5Positioning.so 0xb2d01db8
D/dalvikvm( 4630): Added shared lib /data/local/tmp/qt/lib/libQt5Positioning.so 0xb2d01db8
D/dalvikvm( 4630): No JNI_OnLoad found in /data/local/tmp/qt/lib/libQt5Positioning.so 0xb2d01db8, skipping init
D/dalvikvm( 4630): Trying to load lib /data/local/tmp/qt/lib/libQt5QuickParticles.so 0xb2d01db8
D/dalvikvm( 4630): Added shared lib /data/local/tmp/qt/lib/libQt5QuickParticles.so 0xb2d01db8
D/dalvikvm( 4630): No JNI_OnLoad found in /data/local/tmp/qt/lib/libQt5QuickParticles.so 0xb2d01db8, skipping init
D/dalvikvm( 4630): Trying to load lib /data/local/tmp/qt/plugins/platforms/android/libqtforandroid.so 0xb2d01db8
D/dalvikvm( 4630): Added shared lib /data/local/tmp/qt/plugins/platforms/android/libqtforandroid.so 0xb2d01db8
I/Qt      ( 4630): qt start
D/dalvikvm( 4630): Trying to load lib /data/local/tmp/qt/plugins/bearer/libqandroidbearer.so 0xb2d01db8
D/dalvikvm( 4630): Added shared lib /data/local/tmp/qt/plugins/bearer/libqandroidbearer.so 0xb2d01db8
D/dalvikvm( 4630): No JNI_OnLoad found in /data/local/tmp/qt/plugins/bearer/libqandroidbearer.so 0xb2d01db8, skipping init
D/dalvikvm( 4630): Trying to load lib /data/local/tmp/qt/lib/libQt5QuickParticles.so 0xb2d01db8
D/dalvikvm( 4630): Shared lib '/data/local/tmp/qt/lib/libQt5QuickParticles.so' already loaded in same CL 0xb2d01db8
D/dalvikvm( 4630): Trying to load lib /data/local/tmp/qt/plugins/position/libqtposition_android.so 0xb2d01db8
D/dalvikvm( 4630): Added shared lib /data/local/tmp/qt/plugins/position/libqtposition_android.so 0xb2d01db8
I/QtPositioning( 4630): Positioning start
D/dalvikvm( 4630): GC_CONCURRENT freed 189K, 9% free 2918K/3184K, paused 27ms+24ms, total 266ms
D/dalvikvm( 4630): Trying to load lib /data/app-lib/org.qtproject.example.appTurista-1/libappTurista.so 0xb2cda5c8
D/        ( 4630): (null):0 ((null)): QML debugging is enabled. Only use this in a safe environment.
D/dalvikvm( 4630): Added shared lib /data/app-lib/org.qtproject.example.appTurista-1/libappTurista.so 0xb2cda5c8
D/dalvikvm( 4630): No JNI_OnLoad found in /data/app-lib/org.qtproject.example.appTurista-1/libappTurista.so 0xb2cda5c8, skipping init
I/Qt JAVA ( 4630): DEBUGGER: extra parameters: Bundle[{debug_ping=true, gdbserver_socket=/data/data/org.qtproject.example.appTurista/debug-socket, qml_debug=true, gdbserver_command=/data/data/org.qtproject.example.appTurista/lib/libgdbserver.so --multi +/data/data/org.qtproject.example.appTurista/debug-socket, qmljsdebugger=port:55091,block, ping_socket=org.qtproject.example.appTurista.ping_pong_socket}]
I/Qt JAVA ( 4630): DEBUGGER: removing gdb socket /data/data/org.qtproject.example.appTurista/debug-socket
I/Qt JAVA ( 4630): DEBUGGER: starting /data/data/org.qtproject.example.appTurista/lib/libgdbserver.so --multi +/data/data/org.qtproject.example.appTurista/debug-socket
I/Qt JAVA ( 4630): DEBUGGER: gdbserver started
I/Qt JAVA ( 4630): DEBUGGER: waiting for socket at /data/data/org.qtproject.example.appTurista/debug-socket, attempt 0
I/Qt JAVA ( 4630): DEBUGGER: waiting for socket at /data/data/org.qtproject.example.appTurista/debug-socket, attempt 1
I/Qt JAVA ( 4630): DEBUGGER: socket ok
I/Qt JAVA ( 4630): DEBUGGER: Waiting for debug socket connect
I/Qt JAVA ( 4630): DEBUGGER: go to sleep
I/Qt JAVA ( 4630): DEBUGGER: Waiting for debug socket connect
I/Qt JAVA ( 4630): DEBUGGER: go to sleep
I/Qt JAVA ( 4630): DEBUGGER: Debug socket accepted
I/Qt JAVA ( 4630): DEBUGGER: Waiting for debug socket connect
I/Qt JAVA ( 4630): DEBUGGER: go to sleep
I/Qt JAVA ( 4630): DEBUGGER: Waiting for debug socket connect
I/Qt JAVA ( 4630): DEBUGGER: go to sleep
I/Qt JAVA ( 4630): DEBUGGER: Waiting for debug socket connect
I/Qt JAVA ( 4630): DEBUGGER: go to sleep
I/Qt JAVA ( 4630): DEBUGGER: Waiting for debug socket connect
I/Qt JAVA ( 4630): DEBUGGER: go to sleep
I/Qt JAVA ( 4630): DEBUGGER: Waiting for debug socket connect
I/Qt JAVA ( 4630): DEBUGGER: go to sleep
I/Qt JAVA ( 4630): DEBUGGER: Waiting for debug socket connect
I/Qt JAVA ( 4630): DEBUGGER: go to sleep
I/Qt JAVA ( 4630): DEBUGGER: Waiting for debug socket connect
I/Qt JAVA ( 4630): DEBUGGER: go to sleep
I/Qt JAVA ( 4630): DEBUGGER: Waiting for debug socket connect
I/Qt JAVA ( 4630): DEBUGGER: go to sleep
I/Qt JAVA ( 4630): DEBUGGER: Waiting for debug socket connect
I/Qt JAVA ( 4630): DEBUGGER: go to sleep
I/Qt JAVA ( 4630): DEBUGGER: Waiting for debug socket connect
I/Qt JAVA ( 4630): DEBUGGER: go to sleep
I/Qt JAVA ( 4630): DEBUGGER: Waiting for debug socket connect
I/Qt JAVA ( 4630): DEBUGGER: go to sleep
I/Qt JAVA ( 4630): DEBUGGER: Waiting for debug socket connect
I/Qt JAVA ( 4630): DEBUGGER: go to sleep
I/Qt JAVA ( 4630): DEBUGGER: Waiting for debug socket connect
I/Qt JAVA ( 4630): DEBUGGER: go to sleep
I/Qt JAVA ( 4630): DEBUGGER: Waiting for debug socket connect
I/Qt JAVA ( 4630): DEBUGGER: go to sleep
I/Qt JAVA ( 4630): DEBUGGER: Waiting for debug socket connect
I/Qt JAVA ( 4630): DEBUGGER: go to sleep
I/Qt JAVA ( 4630): DEBUGGER: Waiting for debug socket connect
I/Qt JAVA ( 4630): DEBUGGER: go to sleep
I/Qt JAVA ( 4630): DEBUGGER: Waiting for debug socket connect
I/Qt JAVA ( 4630): DEBUGGER: go to sleep
I/Qt JAVA ( 4630): DEBUGGER: Waiting for debug socket connect
I/Qt JAVA ( 4630): DEBUGGER: go to sleep
I/Qt JAVA ( 4630): DEBUGGER: Waiting for debug socket connect
I/Qt JAVA ( 4630): DEBUGGER: go to sleep
I/Qt JAVA ( 4630): DEBUGGER: Waiting for debug socket connect
I/Qt JAVA ( 4630): DEBUGGER: go to sleep
I/Qt JAVA ( 4630): DEBUGGER: Waiting for debug socket connect
I/Qt JAVA ( 4630): DEBUGGER: go to sleep
I/Qt JAVA ( 4630): DEBUGGER: Waiting for debug socket connect
I/Qt JAVA ( 4630): DEBUGGER: go to sleep
I/Qt JAVA ( 4630): DEBUGGER: Waiting for debug socket connect
I/Qt JAVA ( 4630): DEBUGGER: go to sleep
I/Qt JAVA ( 4630): DEBUGGER: Waiting for debug socket connect
I/Qt JAVA ( 4630): DEBUGGER: go to sleep
I/Qt JAVA ( 4630): DEBUGGER: Waiting for debug socket connect
Could not load shared library symbols for 88 libraries, e.g. /system/bin/linker.
Use the "info sharedlibrary" command to see the complete listing.
Do you need "set solib-search-path" or "set sysroot"?Unable to find dynamic linker breakpoint function.
GDB will be unable to debug shared library initializers
and track explicitly loaded dynamic code.I/Qt JAVA ( 4630): DEBUGGER: go to sleep
I/Qt JAVA ( 4630): DEBUGGER: Incoming socket OK
I/Qt JAVA ( 4630): DEBUGGER: Got pid acknowledgment
I/Qt JAVA ( 4630): DEBUGGER: ping not requested
I/Qt JAVA ( 4630): DEBUGGER: pong not requested
W/Qt A11Y ( 4630): Could not activate platform accessibility.
D/        ( 4630): HostConnection::get() New Host Connection established 0xb7383e58, tid 4666
D/        ( 4630): HostConnection::get() New Host Connection established 0xb73891a8, tid 4630
W/EGL_emulation( 4630): eglSurfaceAttrib not implemented
D/OpenGLRenderer( 4630): Enabling debug mode 0
D/libappTurista.so( 4630): (null):0 ((null)): QML Debugger: Waiting for connection on port 55091...
D/libappTurista.so( 4630): ../appTurista/manejadorbd.cpp:11 (ManejadorBD::ManejadorBD(QObject*)): (ManejadorDB)Apertura de base de datos local: false
D/libappTurista.so( 4630): ../appTurista/manejadorbd.cpp:24 (bool ManejadorBD::cargarDatosDBLocal()): (ManejadorDB)Cargando datos desde DB Local
W/libappTurista.so( 4630): (null):0 ((null)): QSqlQuery::exec: database not open
D/libappTurista.so( 4630): ../appTurista/main.cpp:20 (int main(int, char**)): Error al obtener tamaño de la pantalla.
D/libappTurista.so( 4630): No se puede continuar asi.
D/libappTurista.so( 4630): ../appTurista/globalcontrolclass.cpp:30 (virtual GlobalControlClass::~GlobalControlClass()): (GlobalControlClass)Borrando controlador Global
D/libappTurista.so( 4630): ../appTurista/manejadorbd.cpp:14 (virtual ManejadorBD::~ManejadorBD()): (ManejadorDB)Liberando de memoria lista de promociones y Bases de Datos
D/dalvikvm( 4630): threadid=12: thread exiting, not yet detached (count=0)
Debugging has finished

"org.qtproject.example.appTurista" terminated.

我的main.cpp:
#include <QApplication>
#include <QQmlApplicationEngine>

#include <QDebug>
#include <QScreen>
#include <QQmlContext>
#include "globalcontrolclass.h"

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QQmlApplicationEngine engine;
    GlobalControlClass controlGlobal;

    QRect z = qApp->primaryScreen()->availableGeometry();
    controlGlobal.setWindowHeight(z.height());
    controlGlobal.setWindowWidth(z.width());
    if(z.height()<=0 || z.width()<=0){
        qDebug()<<"Error al obtener tamaño de la pantalla.\nNo se puede continuar asi.";
        return false;
    }
    qDebug()<<"Window Dip-> H:"<<controlGlobal.windowHeight()<<"W:"<<controlGlobal.windowWidth();

    engine.rootContext()->setContextProperty("ControlGlobal", &controlGlobal);
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

    return app.exec();
}

我使用Qt Creator 3.3.1 Qt 5.4.1(GCC 4.6.1,64位)
AMV是ARM(armeabi-v7a)目标:Android 4.4.2(API级别19)

最佳答案

通过以下方式解决我的问题。
qApp->primaryScreen()->availableGeometry();更改为qApp->desktop()->availableGeometry();,如果我得到了可用的屏幕尺寸,则此解决方案对于主要功能很重要,它以以下方式开始QApplication app(argc, argv);
main.cpp:

#include <QApplication>      // <== this is important
#include <QQmlApplicationEngine>

#include <QDebug>            // <= with the intention of testing

#include <QScreen>           // <== this is important
#include <QDesktopWidget>    // <==

#include <QQmlContext>
#include "globalcontrolclass.h"
int main(int argc, char *argv[]){
    QApplication app(argc, argv);
    QQmlApplicationEngine engine;
    GlobalControlClass controlGlobal;

    QRect z = qApp->desktop()->screenGeometry();
    controlGlobal.setWindowHeight(z.height());
    controlGlobal.setWindowWidth(z.width());

    qDebug()<<"Window Dip-> H:"<<controlGlobal.windowHeight()<<"W:"<<controlGlobal.windowWidth();
    if(z.height()<=0 || z.width()<=0){
        qDebug()<<"Error al obtener tamaño de la pantalla.\nNo se puede continuar asi.";
        return false;
    }

    engine.rootContext()->setContextProperty("ControlGlobal", &controlGlobal);
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

    return app.exec();
}

08-26 00:39