07-30-2012 08:44 AM
Hello all,
In my app I use custom qml page (simple text file editor) that have one row with 5 buttons, second row have one textField and the rest of the screen is TextArea, nested/arranged in few containers. Content of TextArea is filled by reading text file:
I use
QTextStream in(&file);
while (!in.atEnd()) {
textHolder->setText(in.readAll().toUtf8());
But, sometimes text is passed in one line to the TextArea, even if the file contains more lines, whitespaces etc. I used the same code for plain Qt program and contents of file is diplayed as it is in the text file.
Next problem, after filling the whole visible TextArea with text input from keyboard, the TextArea scrools automatically but up to certain number of lines (10 +-) and it friezes. I can't scrool it to the top, nor to the bottom. Using resetText() resets the freezed text content, but doesn't return back to top. Tried using ScrollView, but no success. It's preety **bleep** useless.
Also, when virtual keyboard shows up, top of TextArea overlaps the textlabel. Got no idea how to fix this.
I've done the similar thing in Qt for PB, and it works without glitch, but Cascades gives me headaches ![]()
Here is my qml file
import bb.cascades 1.0
import Dialog.FileBrowse 1.0
import Dialog.FileSave 1.0
Page {
content:
Container {
layout: StackLayout {
}
//main container
Container {
layout: StackLayout {
layoutDirection: LayoutDirection.LeftToRight
bottomPadding: 5.0
leftPadding: 5.0
rightPadding: 5.0
topPadding: 5.0
}
// scrollMode: ScrollMode.None
Button {
objectName: "open"
text: "Open"
onClicked: {
filebrowseDialog.show();
}
attachedObjects: [
FileBrowseDialog {
id: filebrowseDialog
objectName: "fb"
multiselect: false
filters: [
"*.doc",
"*.txt",
"*.html",
"*.htm",
"*.dat",
"*.php",
"*.*"
]
onSelectionCompleted: {
if (filebrowseDialog.filepaths.length > 0) {
labelID.text = filebrowseDialog.filepaths[0];
cs.on_openButton_clicked(filebrowseDialog.filepath s[0]);
} else {
labelID.text = "Nothing selected";
}
}
onSelectionCancelled: {
// labelID.text = "File open cancelled";
//simulator test, comment it out for release!!!
labelID.text = "no REAL file selected";
cs.on_openButton_clicked("test.txt");
}
}
]
}
Button {
objectName: "close"
text: "Clear"
}
Button {
objectName: "save"
text: "Save"
}
Button {
objectName: "saveAs"
text: "Save As.."
attachedObjects: [
FileSaveDialog {
id: filesavedialog
objectName: "fs"
// filesave_filename: "test.txt"
onSelectionCompleted: {
labelID.text = "Saved to: " + filesavedialog.filepaths[0];
cs.on_saveAsButton_clicked(filesavedialog.filepath s[0]);
}
}
]
onClicked: {
filesavedialog.show();
}
}
Button {
objectName: "exit"
text: "Exit"
}
}
Container {
leftMargin: 0.0
layout: StackLayout {
leftPadding: 5.0
rightPadding: 5.0
bottomPadding: 5.0
}
Label {
id: labelID
objectName: "documentName"
text: ""
layoutProperties: StackLayoutProperties {
verticalAlignment: VerticalAlignment.Center
horizontalAlignment: HorizontalAlignment.Center
}
}
ScrollView { id: scrollableTextHolder scrollViewProperties.scrollMode: ScrollMode.Vertical Container { TextArea { objectName: "contentHolder" inputMode: TextAreaInputMode.Text preferredWidth: 1270.0 minWidth: 1270.0 maxWidth: 1270.0 preferredHeight: 590.0 minHeight: 590.0 //maxHeight: 2048.0 } } }
}
}
}
Solved! Go to Solution.
07-31-2012 10:33 AM
08-01-2012 11:16 AM
Hi,
Have you tried other values than Utf8()? What results would that give you in your case?
I will look into this today and try to reproduce this issue with a sample textfile;
As for the text freezing of the textarea, I would suggest logging an issue:
https://www.blackberry.com/jira/secure/Dashboard.j
Martin
08-04-2012 10:12 AM
Hello,
I tried everything other that UTF8, but no success.
Currently I'm using this:
QTextStream in(&file);
QString line = "";
QChar theChar;
while (!in.atEnd()) {
in.operator >>(theChar);
qDebug() << "text redden(QChar): " << theChar << endl;
line.append(theChar);
}
textHolder->setText(line);
which reads the data fine from file (text layout is correct with whitespaces and newline chars), but ONLY if file is saved correctly. When I output simple string with:
QTextStream out(&file);
QString testStr("This \n is \n sample \n\r text.");
//QString textFromArea(textHolder->text());
out << testStr;
it's written as-is, and reading the filecontents again provide the result that I need. But when I pass the text from TextArea, again layout of the text is not correct, no whitespaces nor newline characters. Even outputing the contents char by char doesn't help.
I believe that it's TextArea bug or maybe QTextStream fails/rejects to write newline/space characters to the file.
Now, I added tha TextArea to ScrollView, but still can't scroll the text with swipe up/down throught the contents on simulator. Entering random length of text doesn't freeze, but sometimes top left corner goes into infinity and quickly returns back.
And still can't solve the overlappin problem
08-07-2012 02:33 PM
08-08-2012 11:13 AM
Hmm have you tried reading the textfile read only or use readLine to read through it?
When you read in text, what are the integer values of whitespaces? Are they what you expect?
Martin
08-13-2012 03:09 AM - edited 08-13-2012 03:10 AM
Sorry for late reply, I fixed the problem last night. Reading the file with this
QTextStream in(&file); textHolder->setText(in.readAll());
or this
QString line = "";
QChar theChar;
while (!in.atEnd()) {
in.operator >>(theChar);
qDebug() << "text redden(QChar): " << theChar << endl;
qDebug() << "character is(category): " << theChar.category() << endl;
line.append(theChar);
}
textHolder->setText(line);
returned integer values for whitespace and newline characters are OK. Problem comes from saving content to the file.
Somehow QTextStream recognises newline character and whitespace as [QChar:
eparator_Space7Unicode class name Zs] and [QChar:
ther_Control10Unicode class name Cc] which are correct but refuses to write them to the file.
I used this to solve my problem.
QTextStream out(&file);
for(int i=0;i<textHolder->text().length();++i){
qDebug() << "text to be written: " << QChar(textHolder->text().at(i)) << endl;
qDebug() << "character is(category): " << textHolder->text().at(i).category() << endl;
if(textHolder->text().at(i).category() == 10){
out << "\n";
}
else{
out << textHolder->text().at(i);
}
}
out.flush();
08-13-2012 10:39 AM
Excellent!
Let us know if you come across anything else;
Martin
08-13-2012 11:31 AM
08-13-2012 04:05 PM - edited 08-13-2012 04:06 PM
Right-
The issues you are having definitely suggest an bug report and I see that you have already logged one in regards to this:
https://www.blackberry.com/jira/browse/BBTEN-169
This is definitely a critical issue that should be addressed - Thanks;
Martin