Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-36125

No way to assign locale to C++ property

    XMLWordPrintable

    Details

    • Commits:
      7f50eca469a24809d6d5812ee94b447966ff81f9

      Description

      #include <QCoreApplication>
      #include <QDebug>
      #include <QLocale>
      #include <QQmlComponent>
      #include <QQmlEngine>
      
      class CalendarModel : public QObject
      {
          Q_OBJECT
          Q_PROPERTY(QLocale locale READ locale WRITE setLocale)
      public:
          CalendarModel() {
          }
      
          CalendarModel(const CalendarModel &rhs) {
              mLocale = rhs.mLocale;
          }
      
          QLocale locale() const {
              return mLocale;
          }
      
          void setLocale(const QLocale &locale) {
              mLocale = locale;
          }
      private:
          QLocale mLocale;
      };
      
      Q_DECLARE_METATYPE(CalendarModel)
      
      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
          QQmlEngine engine;
          QQmlComponent component(&engine);
          qmlRegisterType<CalendarModel>("Test", 1, 0, "CalendarModel");
          component.setData("import QtQml 2.2\n"
              "import Test 1.0\n"
              "QtObject {"
              //"    property Locale theLocale: Qt.locale()\n"
              "    property var theLocale: Qt.locale()\n"
              "    property CalendarModel model: CalendarModel {"
              "        locale: theLocale"
              "} }", QUrl());
          if (component.isError()) {
              qWarning() << component.errorString();
              return 0;
          } else {
              while (!component.isReady()) {
                  QCoreApplication::processEvents();
              }
              QObject *item = qobject_cast<QObject*>(component.create());
              //qDebug() << item->property("locale").value<Calendar>().locale().name();
          }
      
          return a.exec();
      }
      
      #include "main.moc"
      

      Using var as the property type gives me this error:

      <Unknown File>: Unable to assign QVariantMap to QLocale

      Using Locale as the property type gives me the this error:

      :3 Locale cannot be instantiated. Use Qt.locale()

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            • Assignee:
              mitch_curtis Mitch Curtis
              Reporter:
              mitch_curtis Mitch Curtis
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Gerrit Reviews

                There are no open Gerrit changes