Qt Android and Native Date/TimePickerDialog Appear Different



  • Hi; I wrote Date/TimePickerDialog code in Android/Java. Then when I ran this code with Android Studio on Android 6.0, I see: Android Native Image. Then when I ran this code in Qt / C++, I see: Android Qt Image. Java native code is same but Android native and Qt are differents. Also test device is same (Android 6.0 Phone). Why is different same code is running with Android native and Qt?

    Picker.java:

    package com.xxx.qttest;
    
    import java.util.Calendar;
    import android.app.DatePickerDialog;
    import android.app.TimePickerDialog;
    import android.widget.DatePicker;
    import android.widget.TimePicker;
    import android.widget.Toast;
    import android.content.Context;
    
    public class Picker extends org.qtproject.qt5.android.bindings.QtActivity
    {
        private static Calendar calendar = Calendar.getInstance();
        private static String date, time;
        private static Context c;
    
        public Picker()
        {
        }
    
        public static String datePickerDialog(Context context)
        {
            c = context;
            DatePickerDialog datePickerDialog = new DatePickerDialog(c,
                    new DatePickerDialog.OnDateSetListener() {
                        @Override
                        public void onDateSet(DatePicker datePicker, int i, int i1, int i2) {
                            date = i2 + "/" + i1 + "/" + i;
                            Toast.makeText(c, date, Toast.LENGTH_LONG).show();
                        }
                    }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
            datePickerDialog.show();
    
            return date;
        }
    
        public static String timePickerDialog(Context context)
        {
            c = context;
            TimePickerDialog timePickerDialog = new TimePickerDialog(c,
                    new TimePickerDialog.OnTimeSetListener() {
                        @Override
                        public void onTimeSet(TimePicker timePicker, int i, int i1) {
                            time = i + " : " + i1;
                            Toast.makeText(c, time, Toast.LENGTH_LONG).show();
                        }
                    }, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), false);
            timePickerDialog.show();
    
            return time;
        }
    }
    

    My test.h file:

    #ifndef TEST_H
    #define TEST_H
    
    #include <QObject>
    #include <QtAndroid>
    #include <QAndroidJniObject>
    
    class Test : public QObject
    {
      Q_OBJECT
    public:
      explicit Test(QObject* parent = 0);
      Q_INVOKABLE QString datePickerDialog() const;
      Q_INVOKABLE QString timePickerDialog() const;
    
    signals:
    
    public slots:
    };
    
    #endif
    

    My test.cpp file:

    #include "test.h"
    
    Test::Test(QObject* parent) : QObject(parent)
    {
    }
    
    QString Test::datePickerDialog() const
    {
      QAndroidJniObject datePickerDialog;
      QtAndroid::runOnAndroidThread([&]()
      {
        datePickerDialog = QAndroidJniObject::callStaticObjectMethod(
            "com/xxx/qttest/Picker",
            "datePickerDialog",
            "(Landroid/content/Context;)Ljava/lang/String;",
            QtAndroid::androidActivity().object());
      });
    
      return datePickerDialog.toString();
    }
    
    QString Test::timePickerDialog() const
    {
      QAndroidJniObject timePickerDialog;
      QtAndroid::runOnAndroidThread([&]()
      {
        timePickerDialog = QAndroidJniObject::callStaticObjectMethod(
            "com/xxx/qttest/Picker",
            "timePickerDialog",
            "(Landroid/content/Context;)Ljava/lang/String;",
            QtAndroid::androidActivity().object());
      });
    
      return timePickerDialog.toString();
    }
    

    I want calendar such as Android Native Calendar with Qt, not spinner. How can I do it? Thanks.


Log in to reply
 

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