2017-03-27 25 views

回答

-1

The QT TextField使用中文和日文字符。所以這不是因爲TextField。也許可能會用你的TextField去除文本。 我會給你一個Qt Quick Control 2我用中文字符測試的代碼。

的.pro

QT += qml quick 

CONFIG += c++11 

SOURCES += main.cpp 

RESOURCES += qml.qrc 

# Additional import path used to resolve QML modules in Qt Creator's code model 
QML_IMPORT_PATH = 

# Additional import path used to resolve QML modules just for Qt Quick Designer 
QML_DESIGNER_IMPORT_PATH = 

# The following define makes your compiler emit warnings if you use 
# any feature of Qt which as been marked deprecated (the exact warnings 
# depend on your compiler). Please consult the documentation of the 
# deprecated API in order to know how to port your code away from it. 
DEFINES += QT_DEPRECATED_WARNINGS 

# You can also make your code fail to compile if you use deprecated APIs. 
# In order to do so, uncomment the following line. 
# You can also select to disable deprecated APIs only up to a certain version of Qt. 
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 

# Default rules for deployment. 
qnx: target.path = /tmp/$${TARGET}/bin 
else: unix:!android: target.path = /opt/$${TARGET}/bin 
!isEmpty(target.path): INSTALLS += target 

的main.cpp

#include <QGuiApplication> 
#include <QQmlApplicationEngine> 

int main(int argc, char *argv[]) 
{ 
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 
    QGuiApplication app(argc, argv); 

    QQmlApplicationEngine engine; 
    engine.load(QUrl(QLatin1String("qrc:/main.qml"))); 

    return app.exec(); 
} 

main.qml

import QtQuick 2.7 
import QtQuick.Controls 2.0 
import QtQuick.Layouts 1.0 

ApplicationWindow { 
    visible: true 
    width: 320 
    height: 480 
    title: qsTr("Hello World") 

    SwipeView { 
     id: swipeView 
     anchors.fill: parent 
     currentIndex: tabBar.currentIndex 

     Page1 { 
     } 

     Page { 
      Label { 
       text: qsTr("Second page") 
       anchors.centerIn: parent 
      } 
     } 
    } 

    footer: TabBar { 
     id: tabBar 
     currentIndex: swipeView.currentIndex 
     TabButton { 
      text: qsTr("First") 
     } 
     TabButton { 
      text: qsTr("Second") 
     } 
    } 
} 

Page1.qml

import QtQuick 2.7 

Page1Form { 
    button1.onClicked: { 
     console.log("Button Pressed. Entered text: " + textField1.text); 
     label.text = textField1.text 
    } 
} 

Page1From.ui.qml

import QtQuick 2.7 
import QtQuick.Controls 2.0 
import QtQuick.Layouts 1.0 

Item { 
    property alias textField1: textField1 
    property alias button1: button1 
    property alias label: label 

    GridLayout { 
     id: gridLayout 
     anchors.fill: parent 
     columns: 2 
     rows: 2 

     TextField { 
      id: textField1 
      Layout.fillHeight: true 
      Layout.fillWidth: true 
      placeholderText: qsTr("Text Field") 
     } 

     Button { 
      id: button1 
      text: qsTr("Press Me") 
      Layout.fillHeight: true 
      Layout.fillWidth: true 
     } 

     Label { 
      id: label 
      width: 213 
      height: 54 
      Layout.columnSpan: 2 
      Layout.fillHeight: true 
      Layout.fillWidth: true 
     } 
    } 
} 

qtquickcontrols2.conf

; This file can be edited to change the style of the application 
; See Styling Qt Quick Controls 2 in the documentation for details: 
; http://doc.qt.io/qt-5/qtquickcontrols2-styles.html 

[Controls] 
Style=Material 

[Universal] 
Theme=Dark 
;Accent=Steel 

[Material] 
Theme=Dark 
;Accent=BlueGrey 
;Primary=BlueGray 
+0

@DebashishSamantaray歡迎您:)你能否驗證我的答案plz? ^^ –

+1

我已經在qt字體中添加了特定的xxx.ttf文件,這是lib下它現在工作正常。 –