My first attempt at a plugin: PartsList.qml

• Jul 26, 2020 - 08:20

So, I finally bit the bullet and tried to learn enough Qt to write a plugin. Simple plugin, it creates a text file that lists the parts in a score. Help me out with Version 2 where I'd like to fix/add:
1. Part names with flats (and I suppose sharps) in them show up as question marks in a text editor. I'd like to replace that with a word. But, even if I use QReplace, what do I tell it to replace?
2. On windows, the plugin opens the list in Notepad. There must be a way to determine the OS and then open it in an appropriate editor in other OS's. I'm guessing it will write OK in other OS's, but I don't have any installations to test it in.

Let me know what you think.

https://github.com/jasendorf/PartsList

John


Comments

So, I thought the following might fix my ? problem...

        QString thepartslist = QStringLiteral(curScore.scoreName + " Parts List\n");
        for (var i = 0; i < curScore.parts.length; i++) {
               thepartslist += QStringLiteral(curScore.parts[i].partName + "\n");
        }

But, all that did is break it. Any suggestions are welcome.

In reply to by jeetee

Yeah, I've tried it in a bunch of editors but they all come back with question marks (not the dreaded boxes). So, I'm thinking I actually have question marks meaning that I need to tell Qt what they are or what encoding they're in.

I know how to replace... I just don't know WHAT to tell it to replace.

In reply to by John Asendorf

Internally QTextStream is used in FileIO implementation, and QTextStream documentation has the following statement regarding text encoding:

By default, QTextCodec::codecForLocale() is used for reading and writing, but you can also set the codec by calling setCodec().

Given this, may the issue be in that QTextStream chooses a non-Unicode codec by default on Windows, and this results in most non-ASCII characters be written incorrectly? If so it might be needed to explicitly set the stream codec to UTF-8 or at least expose an ability to set encoding of the written text to FileIO interface.

I am not on Windows to check this but perhaps someone could verify my guess there.

Do you still have an unanswered question? Please log in first to post your question.