• <tfoot id='Oy2hO'></tfoot>
    <legend id='Oy2hO'><style id='Oy2hO'><dir id='Oy2hO'><q id='Oy2hO'></q></dir></style></legend>

  • <i id='Oy2hO'><tr id='Oy2hO'><dt id='Oy2hO'><q id='Oy2hO'><span id='Oy2hO'><b id='Oy2hO'><form id='Oy2hO'><ins id='Oy2hO'></ins><ul id='Oy2hO'></ul><sub id='Oy2hO'></sub></form><legend id='Oy2hO'></legend><bdo id='Oy2hO'><pre id='Oy2hO'><center id='Oy2hO'></center></pre></bdo></b><th id='Oy2hO'></th></span></q></dt></tr></i><div id='Oy2hO'><tfoot id='Oy2hO'></tfoot><dl id='Oy2hO'><fieldset id='Oy2hO'></fieldset></dl></div>

      <bdo id='Oy2hO'></bdo><ul id='Oy2hO'></ul>
  • <small id='Oy2hO'></small><noframes id='Oy2hO'>

        如何使 QML TextField 绑定在 Android 下工作?

        How to make QML TextField binding work under Android?(如何使 QML TextField 绑定在 Android 下工作?)
      1. <small id='4oICT'></small><noframes id='4oICT'>

          <bdo id='4oICT'></bdo><ul id='4oICT'></ul>
        • <i id='4oICT'><tr id='4oICT'><dt id='4oICT'><q id='4oICT'><span id='4oICT'><b id='4oICT'><form id='4oICT'><ins id='4oICT'></ins><ul id='4oICT'></ul><sub id='4oICT'></sub></form><legend id='4oICT'></legend><bdo id='4oICT'><pre id='4oICT'><center id='4oICT'></center></pre></bdo></b><th id='4oICT'></th></span></q></dt></tr></i><div id='4oICT'><tfoot id='4oICT'></tfoot><dl id='4oICT'><fieldset id='4oICT'></fieldset></dl></div>

            <legend id='4oICT'><style id='4oICT'><dir id='4oICT'><q id='4oICT'></q></dir></style></legend>
                <tbody id='4oICT'></tbody>
              <tfoot id='4oICT'></tfoot>

                • 本文介绍了如何使 QML TextField 绑定在 Android 下工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我目前正在尝试为 Android 编写 QML/C++ 应用程序.在我的代码中,我有一个如下所示的类:

                  I am currently trying to write a QML/C++ application for Android. Somewhere in my code, I have a class that looks like this:

                  class MyClass : public QObject
                  {
                    Q_OBJECT
                  
                    Q_PROPERTY(QString prop READ prop WRITE setProp NOTIFY propChanged)
                  
                  public:
                    explicit MyClass(QObject* a_Parent = 0);
                  
                    QString prop() const
                    {
                      return m_Prop;
                    }
                  
                    void setProp(const QString& a_Value)
                    {
                      m_Prop = a_Value;
                      emit propChanged();
                    }
                  
                  signals:
                    void propChanged();
                  
                  private:
                    QString m_Prop;
                  };
                  

                  在我的 QML 内容中,我有一个按以下方式定义的项目:

                  Somwhere in my QML stuff, I have an Item defined in the following way:

                  ColumnLayout {
                    TextField {
                      id: myField
                      placeholderText: qsTr("Enter text")
                      Layout.fillWidth: true
                      Binding {
                        target: myClass
                        property: "prop"
                        value: myField.text
                      }
                  }
                  

                  当然,我做了一切必要的事情来使 MyClass 类型的对象 myClass 在 C++ 和 QML 之间共享(作为上下文属性).

                  Of course, I did everything necessary to make the object myClass of type MyClass shared between C++ and QML (as a context property).

                  现在,问题如下:无论我在上面的文本字段中输入什么,在 Android 下,最后一个词永远不会从 myField.text 传递到 MyClass.m_Prop.例如,如果我在 TextField 中键入文本我对此 TextField 不满意",则 myClass.m_Prop 将包含我对此不满意".但是,如果我键入我对此 TextField 不满意"(注意空格),然后删除最后一个空格,则所需的字符串将存储在 m_Prop 变量中.

                  Now, the problem is the following: whatever I'm typing in the above textfield, under Android, the last word is never communicated from myField.text to MyClass.m_Prop. For example, if I type the text "I am not happy with this TextField" in the TextField, then myClass.m_Prop will contain "I am not happy with this". However, if I type "I am not happy with this TextField " (notice the space) and then remove the last space, then the desired string is stored in the m_Prop variable.

                  奇怪的是,这在 Linux 下运行得非常好.有人能告诉我我在这里想念什么吗?我正在使用 Qt 5.7 和 Android 6.0.

                  Strange is, that this works perfectly fine under Linux. Can someone tell me what I am missing here? I am working with Qt 5.7 and Android 6.0.

                  感谢您的帮助...

                  推荐答案

                  据我了解对我的问题的评论,我有几种可能解决这个问题.最简单的一种是像这样修改我的 QML 项:

                  As far as I understand the comments to my question, I have a few possibilities to solve this problem. The simplest one is to modify my QML item like this:

                  ColumnLayout {
                    TextField {
                      id: myField
                      placeholderText: qsTr("Enter text")
                      Layout.fillWidth: true
                      Binding {
                        target: myClass
                        property: "prop"
                        value: myField.displayText
                      }
                  }
                  

                  如果我不想允许预测文本输入,那么我可以添加

                  If I didn't want to allow predictive text input, then I could just add the

                  inputMethodHints: Qt.ImhNoPredictiveText
                  

                  在文本字段上.就我而言,我想要预测文本输入.

                  on the TextField. In my case, I want predictive text input.

                  最后,当我单击应用程序的完成"按钮时,我可以调用 QInputMethod::commit(),这将在 Android 上提交显示的文本,然后在 MyClass 中使用提交的文本.在这种情况下,我不应该使用 QML 的绑定功能.相反,我应该将数据提交给 Android,然后将我的 QML 数据传递给 myClass.

                  Last, I could call QInputMethod::commit() when I click the button "Done" of my application, which will commit the displayed text on Android and then use the committed text in MyClass. In this case, I should not use QML's Binding feature. Instead, I should just commit the data to Android and then communicate my QML data to myClass.

                  最适合 QML 哲学的最简单的解决方案可能是使用 displayText 而不是 text,这是我选择的解决方案.

                  The simplest solution that best fits QML philosophy is probably to use displayText instead of text, which is the solution I am choosing.

                  这篇关于如何使 QML TextField 绑定在 Android 下工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Android - Is it possible to get install referrer programmatically(Android - 是否有可能以编程方式安装引荐来源网址)
                  How to sign an APK with more than one certificate?(如何使用多个证书签署 APK?)
                  versionCode vs versionName in Android Manifest(Android Manifest 中的 versionCode 与 versionName)
                  What does this Google Play APK publish error message mean?(这个 Google Play APK 发布错误消息是什么意思?)
                  Lost my keystore for uploaded app on android market(丢失了我在 android 市场上上传的应用程序的密钥库)
                  App on Google Play always shows quot;Updatequot; instead of open(Google Play 上的应用程序总是显示“更新;而不是打开)
                      <tbody id='tTB2m'></tbody>
                    <i id='tTB2m'><tr id='tTB2m'><dt id='tTB2m'><q id='tTB2m'><span id='tTB2m'><b id='tTB2m'><form id='tTB2m'><ins id='tTB2m'></ins><ul id='tTB2m'></ul><sub id='tTB2m'></sub></form><legend id='tTB2m'></legend><bdo id='tTB2m'><pre id='tTB2m'><center id='tTB2m'></center></pre></bdo></b><th id='tTB2m'></th></span></q></dt></tr></i><div id='tTB2m'><tfoot id='tTB2m'></tfoot><dl id='tTB2m'><fieldset id='tTB2m'></fieldset></dl></div>

                        <small id='tTB2m'></small><noframes id='tTB2m'>

                          <legend id='tTB2m'><style id='tTB2m'><dir id='tTB2m'><q id='tTB2m'></q></dir></style></legend>
                            <bdo id='tTB2m'></bdo><ul id='tTB2m'></ul>

                            <tfoot id='tTB2m'></tfoot>