Chinese character doesn’t display correctlly in qml when the content to display is vast
-
是为嵌入式Linux编译的版本。
能详细说一下你所说的载入策略吗?具体怎么使用?
我的configure参数就是再普通不过的参数了,没有什么特殊的配置。 -
虽然我没有做过嵌入式,但是我知道一点,如果内存占用比较大的话,会造成溢出。
你这种情况,嵌入式系统没有显卡吧?那么系统显示相关的部分被文字溢出的那部分影响到了。我曾经搞过CUDA,有一次就不小心访问了不该访问的显存,造成了电脑文字渲染变花。
如果能做到懒加载策略,你的问题应该不会存在了。 -
首先谢谢你的回复。
我使用的是freescale 的imx6s,没有显卡的。
你所指的懒加载是怎么个策略?是指文字显示还是字库的加载? -
懒加载策略参见手机微博客户端,大概就是这个意思。或者说只要不被显示的部分就在内存中销毁。
-
问题大体上可以定位了,和内存泄露或溢出没有关系,是QML的gridview通过model现实数据时就会出现花屏的。
具体QML的bug还是使用不当还没有查清楚。 -
!https://bugreports.qt-project.org/secure/thumbnail/37090/_thumb_37090.png(blurred text)!
哪位高人给看看是否是代码存在缺陷而导致花屏还是QML本身的缺陷。
"https://bugreports.qt-project.org/secure/attachment/37048/GridView.tar.bz2":https://bugreports.qt-project.org/secure/attachment/37048/GridView.tar.bz2
代码如下:
@//Gridview.proAdd more folders to ship with the application, here
Additional import path used to resolve QML modules in Creator's code model
QT += qml quick
QML_IMPORT_PATH = ./
The .cpp file which was generated for your project. Feel free to hack it.
SOURCES += main.cpp
listmodel.cppInstallation path
target.path =
HEADERS +=
listmodel.hOTHER_FILES +=
gridview.qml
database.txt//main.cpp
#include <QGuiApplication>
#include <qqmlengine.h>
#include <qqmlcontext.h>
#include <qqml.h>
#include <QtQuick/qquickitem.h>
#include <QtQuick/qquickview.h>#include <QTextCodec>
#include "listmodel.h"
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);//QTextCodec *codec=QTextCodec::codecForName("UTF-8"); //QTextCodec::setCodecForLocale(codec); ListModel model(NULL,3); QQuickView view; //view.setResizeMode(QQuickView::SizeRootObjectToView); view.setGeometry(100,100,1000,400); view.setMaximumSize(view.size()); view.setMinimumSize(view.size()); //view.setSurfaceType(QSurface::OpenGLSurface); //view.setPersistentOpenGLContext(false); QQmlContext *ctxt = view.rootContext(); ctxt->setContextProperty("DataModel", &model); view.setSource(QUrl("./gridview.qml")); view.show(); return app.exec();
}
//listmodel.h
#ifndef LISTMODEL_H
#define LISTMODEL_H#include <QAbstractListModel>
#include <QStringList>#include <QDebug>
#define ENCODE_NAME "UTF-8"
enum DATA_TYPE
{
ITEM_BINARY,
ITEM_STRING
};class CListItem
{
public:
CListItem();
~CListItem();void pushData(DATA_TYPE type, const void * data, int size); void setData(int index, DATA_TYPE type, void * data, int size); QString getData(int index);
protected:
QList<QString> item;
};class ListModel: public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(int currentIndex READ getCurrentIndex WRITE setCurrentIndex)
Q_PROPERTY(int showNum READ getShowNum)public:
ListModel(QObject *parent,int colcount);
~ListModel();enum ListModelRoles { UserDataRole = Qt::UserRole + 1, }; void addItem(CListItem * item); void removeItem(int index); void modifyItem(int row, int col, DATA_TYPE type, void * data, int size); int rowCount(const QModelIndex & parent = QModelIndex()) const; QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; QHash<int, QByteArray> roleNames() const; int getCurrentIndex(); void setCurrentIndex(int index); int getTotalRecNum(); void showContactData(int m_Booknum, int index); int getShowNum();
signals:
void indexChanged();protected:
QList<CListItem *> items;
QHash<int, QByteArray> roles;
int colCount;
int currIndex;
};#endif // LISTMODEL_H
@ -
@//listmodel.cpp
#include <QFile>
#include <QTextStream>
#include <QTextCodec>
#include <QStringList>#include "listmodel.h"
CListItem::CListItem()
{
//do nothing
}CListItem::~CListItem()
{
item.clear();
}void CListItem::pushData(DATA_TYPE type, const void * data, int size)
{
if(type == ITEM_BINARY)
{
//do nothing
}
else
{
item.append(QString(QByteArray((const char *)data,size)));
}
}void CListItem::setData(int index, DATA_TYPE type, void * data, int size)
{
Q_UNUSED(index);
Q_UNUSED(data);
Q_UNUSED(size);if(type == ITEM_BINARY) { //do nothing } else { //do nothing }
}
QString CListItem::getData(int index)
{
return item.at(index);
}ListModel::ListModel(QObject *parent,int colcount): QAbstractListModel(parent)
{
int index = 0;
colCount = colcount;
QString strTmp=QString();
for(index = 0; index < colCount; index++)
{
strTmp.clear();
strTmp = strTmp.sprintf("col%d",index);
roles[UserDataRole + index] = strTmp.toLocal8Bit();
}currIndex = 1; showContactData(getShowNum(),currIndex);
}
ListModel::~ListModel()
{
//do nothing
// for(int index=0;index<items.count()-1;index++)
// {
// delete items.at(index);
// }
// beginRemoveRows(QModelIndex(),0,rowCount());
// endRemoveRows();
// items.clear();
// resetInternalData();
}void ListModel::addItem(CListItem * item)
{
beginInsertRows(QModelIndex(), rowCount(), rowCount());
items.append(item);
endInsertRows();
}void ListModel::removeItem(int index)
{
Q_UNUSED(index);
//do nothing
}void ListModel::modifyItem(int row, int col, DATA_TYPE type, void * data, int size)
{
Q_UNUSED(row);
Q_UNUSED(col);
Q_UNUSED(type);
Q_UNUSED(data);
Q_UNUSED(size);
//do nothing
}int ListModel::rowCount(const QModelIndex & parent) const
{
Q_UNUSED(parent);
return items.count();
}QVariant ListModel::data(const QModelIndex & index, int role) const
{
if (index.row() < 0 || index.row() >= rowCount())
{
return QVariant();
}CListItem *item = items.at(index.row()); if (role >= UserDataRole) { return QVariant(item->getData(role-UserDataRole)); } else { return QVariant(); }
}
QHash<int, QByteArray> ListModel::roleNames() const
{
return roles;
}int ListModel::getCurrentIndex()
{
return this->currIndex;
}void ListModel::setCurrentIndex(int index)
{
this->currIndex = index;
//emit indexChanged();
showContactData(getShowNum(),this->currIndex);
}#define DATABASE_NAME "./database.txt"
int ListModel::getTotalRecNum()
{
int listnum;
QTextCodec *codec=QTextCodec::codecForName(ENCODE_NAME);
QFile file(DATABASE_NAME);
file.open(QIODevice::ReadOnly);
QTextStream reader(&file);
reader.setCodec(codec);
listnum=1;
while(!reader.readLine().isNull()) {listnum++;}
file.close();
return listnum;
}//get record data from local file
//local file is encoded by utf-8
//m_Booknum:fetch count each time
//index:the range of index to fetch,for example,1-10,11-20,21-30
void ListModel::showContactData(int m_Booknum, int index)
{
// //beginResetModel();
// for(int index=0;index<items.count()-1;index++)
// {
// delete items.at(index);
// }
// beginRemoveRows(QModelIndex(),0,rowCount());
// endRemoveRows();
// items.clear();
// resetInternalData();
// //endResetModel();QTextCodec *codec=QTextCodec::codecForName(ENCODE_NAME); QFile file(DATABASE_NAME); file.open(QIODevice::ReadOnly); QTextStream reader(&file); reader.setCodec(codec); QString Line=""; bool bln=true; while(!Line.isNull()) { Line=reader.readLine(); if(Line.split(":").at(0).toLong(&bln) == index) { break; } } int myIndex =0; for(myIndex=0;myIndex < m_Booknum;myIndex++) { if(!Line.isNull()) { CListItem *item = new CListItem(); QList<QString> spList; spList = Line.split(":"); item->pushData(ITEM_STRING,spList.at(1).toUtf8().data(),spList.at(1).toUtf8().length()); item->pushData(ITEM_STRING,spList.at(2).toUtf8().data(),spList.at(2).toUtf8().length()); item->pushData(ITEM_STRING,spList.at(3).toUtf8().data(),spList.at(3).toUtf8().length()); addItem(item); Line=reader.readLine(); qDebug() << "fetching data... ..." << myIndex+1; } else { break; } } file.close();
}
int ListModel::getShowNum()
{
return 20;
}@
-
@//gridview.qml
import QtQuick 2.0Rectangle {
width: 1000; height: 400
color: "white"//DataModel.showNum:default is 20 property int contactIndex: DataModel.showNum property int maxPosX:0 property int fontsize:30 property string fontname: "宋体" property string fontcolor: "white" Component { id: modelDelegate Item { width: 200; height: 200 Rectangle { x:10 y:10 width: 180; height: 180 radius:15 color:"#282828" Text { id:firstName y: 20; font.pixelSize : fontsize //font.family: fontname color:fontcolor anchors { horizontalCenter: parent.horizontalCenter } //renderType:Text.QtRendering //textFormat:Text.PlainText antialiasing:true text: col0 } Text { id:lastName y: 60; font.pixelSize : fontsize font.family: fontname color:fontcolor anchors { horizontalCenter: parent.horizontalCenter } //renderType:Text.NativeRendering //textFormat:Text.PlainText antialiasing:true font.capitalization:Font.AllLowercase text: col1 } Text { id:contactNumber y: 120; font.pixelSize : 20 font.family: fontname color:fontcolor anchors { horizontalCenter: parent.horizontalCenter } text: col2 } } } } Component { id: itemHighlight Rectangle { width: 180; height: 180; color: "red" } } GridView { anchors.fill: parent cellWidth: 200; cellHeight: 200 highlight: itemHighlight focus: true flow:GridView.TopToBottom layoutDirection:Qt.LeftToRight model: DataModel delegate: modelDelegate //currentIndex:-1 //cacheBuffer:500 populate: Transition { NumberAnimation { properties: "x,y"; duration: 800 } } snapMode:GridView.SnapToRow onFlickEnded: { //if flick to left then fetch data if (contentX >= maxPosX) { maxPosX = contentX //DataModel.showNum:default is 20 contactIndex = contactIndex + DataModel.showNum DataModel.currentIndex = contactIndex } } }
}
@ -
//database.txt
1 :应:用网:268272005179
2 :易:首页:120833637064
3 :欢:迎您:414447531903
4 :安:全退:173395320420
5 :出:微博:125426977250
6 :邮:箱支:102885585596
7 :付:人民:751030750109
8 :网:海南:192095842147
9 :视:窗月:176418287893
10 :日:电近:160073325236
11 :日:海南:373290680377
12 :省:第二:184158916726
13 :中:级人:152332696404
14 :民:法院:110102756857
15 :就:备受:651770108192
16 :媒:体关:321272084251
17 :注:的成:195969428173
18 :都:女子:781391289232
19 :李:靖澜:315841211951
20 :涉:嫌诈:355689419549
21 :骗:一案:211941427311
22 :作:出二:955571796009
23 :审:判决:255316430295
24 :认:为该:100111260469
25 :案:一审:191062013444
26 :审:判程:810181455641
27 :序:违法:113989429322
28 :撤:销白:122462898754
29 :沙:黎族:129019204832
30 :自:治县:130177354708
31 :法:院作:356409173710
32 :出:的一:142157989866
33 :审:判决:966498972805
34 :并:发回:754956681892
35 :重:审据:122292775043
36 :媒:体此:130288589442
37 :前:报道:167944818461
38 :一:年前:172080133273
39 :岁:的成:111463746542
40 :都:女子:647386151035
41 :李:靖澜:187810033284
42 :被:曾经:155800602812
43 :先:后担:204946725517
44 :任:海南:198475481295
45 :湖:北两:115638320671
46 :地:副省:305175763940
47 :长:的孟:990708885468
48 :某:指称:504547666326
49 :其:诈骗:184865584447
50 :了:他的:449388324773
51 :钱:财李:167159632105
52 :靖:澜在:180880763687
53 :投:案后:213714639833
54 :被:取保:214336245698
55 :候:审一:131106491897
56 :年:后的:841392613317
57 :年:月日:570765049068
58 :她:被白:637375024988
59 :沙:县警:180128293428
60 :方:再次:509062487876
61 :以:涉嫌:805862930680
62 :诈:骗刑:198586716029
63 :拘:日被:145194043778
64 :当:地检:120526105741
65 :察:院批:188444725589
66 :捕:并在:196990170437
67 :日:起诉:591507055322
68 :至:法院:585094700076
69 :日:当地:126048583116
70 :法:院审:148190838373
71 :理:了这:179585206198
72 :一:案件:155761343494
73 :并:作出:103971760056
74 :判:决以:440293249476
75 :诈:骗罪:159458262590
76 :名:成立:100438421451
77 :判:处李:981875538956
78 :靖:澜有:203500673977
79 :期:徒刑:159608756642
80 :二:年零:232153432774
81 :六:个月:128436858284
82 :并:处罚:825950614970
83 :金:元有:157586901774
84 :法:律人:130563404667
85 :士:说白:122724627540
86 :沙:县公:774717205200
87 :检:法机:324936287248
88 :关:这样:482627880537
89 :的:办案:911535927842
90 :过:程堪:172139022250
91 :称:神速:110868313555
92 :公:检法:212255501853
93 :神:速办:161133326818
94 :案:拘捕:740888759669
95 :诉:判一:362298071384
96 :周:完成:140927864574
97 :根:据白:105463614133
98 :沙:县今:136229832873
99 :年:月日:150029483091
100 :检:察院:108231396040 -
101 :制:作的:316233805129
102 :白:检刑:203592279052
103 :诉:号起:303539959030
104 :诉:书显:194058808039
105 :示:年月:148557258672
106 :日:年月:649741710105
107 :日:被告:914545808875
108 :人:李靖:150886644864
109 :澜:分别:207243395610
110 :在:海南:146476514827
111 :省:白沙:328535058050
112 :县:七坊:188084848509
113 :镇:海南:176169645547
114 :椰:花香:124792284945
115 :酒:业有:410259871335
116 :限:公司:381404272729
117 :和:山东:175207792260
118 :省:邹平:101897559430
119 :黛:溪山:333507904975
120 :庄:两地:108041642671
121 :与:椰花:156945666249
122 :香:酒公:869593889959
123 :司:法人:599424351084
124 :代:表孟:121939441183
125 :某:洽谈:146273675019
126 :有:关酒:162055920787
127 :业:合作:154779860549
128 :事:宜时:101904102650
129 :李:谎称:263757183628
130 :自:己是:788588830834
131 :某:机构:178957057113
132 :负:责人:752470258429
133 :谢:某某:110848683896
134 :助:理兼:142144903427
135 :主:任为:913826054715
136 :促:成合:224432433601
137 :作:李要:203539933295
138 :求:孟先:197546344106
139 :加:入该:117823756030
140 :机:构并:741804810419
141 :交:纳元:101138545952
142 :会:费年:803965396984
143 :月:日孟:181593974627
144 :在:海口:679382495067
145 :市:向李:977884174976
146 :提:供的:582935437595
147 :地:址汇:210750561337
148 :款:元同:638487372326
149 :年:月日:158483322864
150 :李:在山:121625366640
151 :东:省济:420205565185
152 :南:市邮:163227157102
153 :政:局邮:179977799377
154 :电:支局:852581518899
155 :将:该款:107393863927
156 :提:取但:190852630416
157 :未:帮孟:588889767466
158 :办:理入:213250071239
159 :会:事宜:122763886857
160 :案:发后:108290285017
161 :年:月日:113917453906
162 :被:告人:416083336813
163 :李:靖澜:180749899294
164 :到:四川:134378101716
165 :省:成都:140993296770
166 :市:公安:424196929165
167 :局:金牛:180560145924
168 :分:局营:264411505592
169 :门:口派:235686771379
170 :出:所投:159327398197
171 :案:白沙:673362733000
172 :县:检察:201766720773
173 :院:认为:613361408914
174 :被:告人:721062804164
175 :李:靖澜:300726374586
176 :无:视国:157174678936
177 :法:采用:178943970674
178 :虚:构事:151796152394
179 :实:隐瞒:128692043850
180 :真:相的:160204189629
181 :方:法骗:541844018265
182 :取:他人:309756017687
183 :财:物数:346790640841
184 :额:较大:130798960574
185 :其:行为:172858776410
186 :已:经触:182804470260
187 :犯:刑法:451482155057
188 :的:有关:247857159907
189 :规:定应:118608942387
190 :当:以诈:305568357118
191 :骗:追究:243931228124
192 :其:刑事:974481700764
193 :责:任白:161277277650
194 :沙:县法:147111207132
195 :院:月日:116515112103
196 :作:出的:158411347448
197 :白:刑初:936334730272
198 :字:第号:432964843480
199 :刑:事判:149270469613
200 :决:书显:622521916408
201 :示:李靖:936269298075
202 :澜:在年:498331607669
203 :月:日因:123895863855
204 :涉:嫌诈:114185725911
205 :骗:被白:134790324553
206 :沙:县公:343453598825
207 :安:局刑:108087445208
208 :事:拘留:206477838913
209 :月:日被:149172321318
210 :取:保候:198279184706
211 :审:年月:407249990301
212 :日:又因:720277617808
213 :本:案被:382385755675
214 :白:沙县:213367849192
215 :公:安局:980763191617
216 :刑:事拘:213976368618
217 :留:月日:209055867450
218 :被:执行:134037854295
219 :逮:捕白:202381783419
220 :沙:县检:938493992752
221 :察:院于:199718693026
222 :月:日向:103840895663
223 :白:沙县:191807940483
224 :法:院提:621802162248
225 :起:公诉:487338998676
226 :白:沙县:164889134890
227 :法:院于:880586498952
228 :同:日决:433030275677
229 :定:受理:134659460160
230 :并:于月:129529575964
231 :日:开庭:968265642108
232 :审:理此:999869392962
233 :案:当天:128175129498
234 :即:作出:136085882041
235 :判:决刑:183269038855
236 :事:案件:177694215723
237 :确:实可:133952792439
238 :以:当庭:154563934301
239 :作:出判:121298205658
240 :决:但从:804292557966
241 :整:个案:395079601773
242 :件:办理:158208507639
243 :情:况来:119021165224
244 :看:这个:194052264819
245 :案:子确:520709418833
246 :实:办得:405090727820
247 :有:点过:129653897137
248 :快:了海:149761211086
249 :南:一家:125341915395
250 :律:师事:753190012590
251 :务:所的:106013244583
252 :陈:律师:172348405278
253 :在:看过:158817027066
254 :李:靖澜:131224269850
255 :一:案的:133010568811
256 :相:关材:148177751933
257 :料:后对:172492356110
258 :记:者说:319701711538
259 :目:前刑:123503270677
260 :事:案件:186043363982
261 :超:期审:195439427382
262 :理:的情:131793529959
263 :况:比较:156016529060
264 :多:见但:926519900814
265 :快:捕快:143172188910
266 :诉:快判:209369941993
267 :的:案例:675391131088
268 :确:实不:122037589478
269 :是:很多:655696039976
270 :据:悉白:372898087199
271 :沙:县公:232742322542
272 :安:局最:186324722426
273 :初:接到:182503482157
274 :孟:某报:159582583763
275 :案:后上:332068396654
276 :网:追逃:700909687678
277 :李:靖澜:170123710601
278 :的:内容:164234812926
279 :是:称其:137427242067
280 :涉:嫌诈:175809768467
281 :骗:亿元:116868445963
282 :李:家人:961068100505
283 :得:知后:876856863758
284 :被:吓坏:640515770414
285 :了:带其:998168155856
286 :至:成都:107459296123
287 :市:金牛:327291846318
288 :分:局营:692599798737
289 :门:口派:158228137298
290 :出:所投:672970139821
291 :案:自首:177242733568
292 :后:经成:205627220360
293 :都:警方:187247316395
294 :与:白沙:155447268952
295 :警:方核:643329354859
296 :实:涉案:202394869858
297 :金:额亿:272786826729
298 :元:系白:140940951013
299 :沙:警方:168298152322
300 :笔:误正:112471402366