[QScintilla] Strings with \0 charaters in it?
Matic Kukovec
kukovecmatic at hotmail.com
Tue Apr 25 19:34:02 BST 2017
> > On 25 Apr 2017, at 6:16 pm, Matic Kukovec <kukovecmatic at hotmail.com> wrote:
> > >
> > >
> > > > On 25 Apr 2017, at 5:08 pm, Matic Kukovec <kukovecmatic at hotmail.com> wrote:
> > > > >
> > > > > Hi guys,
> > > > >
> > > > > I just noticed that when adding strings that contain null characters ('\0') using the setText method,
> > > > > QScintilla cuts off the string at the first null character it finds. To be sure I opened the same text saved
> > > > > to a file with Notepad++ and SciTE and there the null characters appear.
> > > > >
> > > > > Is this a bug or should strings with null characters be handled differently?
> > > > > I used this example to for testing:
> > > > > qscieditor.setText("Test\nText\nIn\n\0An\nQscintilla\nEditor")
> > > >
> > > > Is that C++ or Python?
> > > >
> > > > setText() uses the low-level Scintilla SCI_SETTEXT which accepts a '\0' string, ie. you will get the same result if you used Scintilla.
> > > >
> > > > Phil
> > >
> > > Hi Phil,
> > >
> > > I'm using Python3 and before I tried setText and now I tried as you suggested:
> > > qscieditor.SendScintilla(SCI_SETTEXT, bytes("Test\nText\nIn\n\0An\nQscintilla\nEditor", encoding="ascii"))
> > > and I get the same result.
> > > I looked into the C++ setText method and it uses this line:
> > > SendScintilla(SCI_SETTEXT, ScintillaBytesConstData(textAsBytes(text)));
> > > Is there maybe an error in how the ScintillaBytesConstData or textAsBytes convert the text?
> > > I'm only guessing here.
> >
> > You misunderstand. I was saying that the behaviour you see is the way Scintilla works.
> >
> > Phil
>
> Are you sure?
> Then how do SciTE and Notepad++ do this without cutting off at the first '\0' character as they also use Scintilla?
>
> Thanks,
> Matic
Hey Phil,
In the attachment I added the test text file and the screenshots of how the SciTE opens the file and how a simple QScintilla editor opens the file. The code for the simple QScintilla editor is:
editor = PyQt5.Qsci.QsciScintilla()
editor.setMarginWidth(0, "00000")
text = open("test.txt", "r").read()
editor.setText(text)
How can I display the file in QScintilla the same as in SciTE?
I apologize if this is trivial or if not understanding something fundamental.
Thanks,
Matic
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/qscintilla/attachments/20170425/59859ab3/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qscintilla.jpg
Type: image/jpeg
Size: 30699 bytes
Desc: qscintilla.jpg
URL: <https://www.riverbankcomputing.com/pipermail/qscintilla/attachments/20170425/59859ab3/attachment-0002.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: scite.jpg
Type: image/jpeg
Size: 63118 bytes
Desc: scite.jpg
URL: <https://www.riverbankcomputing.com/pipermail/qscintilla/attachments/20170425/59859ab3/attachment-0003.jpg>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: test.txt
URL: <https://www.riverbankcomputing.com/pipermail/qscintilla/attachments/20170425/59859ab3/attachment-0001.txt>
More information about the QScintilla
mailing list