Qt for android



  • how to port existing qwidget application to android device using qt ?
    description
    I have one desktop application developed using QT qwidget feature.how can i port this application to android devices without any code changes? is there any way out ? or i should try the qt quick application feature ?.also which one is better qt quick or qwidget?


  • Moderators

    @diva

    Assuming that your application is already suitable for typical android screen sizes, you can recompile your application and run it on Android.

    Also the use of simple C++ GUI features is possible. AFAIK the use of Qt Quick provides you better visual appearances for your GUI. At least that my conclusions after my post here I had found a couple of posts outside of this forum addressing similar issues, but answers referred only to Qt quick.

    I would love to get corrected on current view.



  • @koahnig thanks for your reply.actually iam able to compile the application to android platform and it is producing .apk also, but the problem is application is crashing when it is installed on the android device.according to me it is not suitable for android screen sizes.how can i make it suitable for android screen ?.what is your opinion?


  • Moderators

    @diva said in Qt for android:

    how can i make it suitable for android screen

    check the screen size and resize it accordingly.

    QScreen *screen = QApplication::screens().at(0);
    screen->availableSize();
    

    Also you may want to read this.

    but the problem is application is crashing when it is installed on the android device

    see the logcat (via adb) on the device. It will show you where exactly it crashed.

    1. connect via adb to your device
    2. start logcat (maybe clear it's buffer make the searching easier)
    3. start your apk
    4. after it crashed, inspect the logcat


  • HI, i tried your solution you have provided i got the following error
    F libc : Fatal signal 11 (SIGSEGV), code 2, fault addr 0xf2b32000 in tid 6958 (QtThread)

    application works on desktop ,but crashing on android emulator.

    following is the code with which i had tried
    mainwindow.cpp

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QScreen>
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        QScreen *screen = QApplication::screens().at(0);
        screen->availableSize();
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    

    main.cpp

    #include "mainwindow.h"
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MainWindow w;
        w.show();
    
        return a.exec();
    }
    

    [edit:koahnig: code tags added]



  • As Android has only one screen, there is no need to use screens() . I wouldn't be surprised it it crashes or returns null, making the next call crash...

    If your code without it crashes, find out why. Of course it shouldn't crash when it is installed. No QMainWindow-related code will be executed when an app is installed.

    Make sure your UI code uses layouts and no hard coded dimensions. If it fails during execution, run it step by step in debugger to see where exactly it fails.


  • Banned

    This post is deleted!

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.