Summary: | Qyoto has severely broken QFile class | ||
---|---|---|---|
Product: | [Unmaintained] bindings | Reporter: | roland |
Component: | general | Assignee: | kde-bindings |
Status: | RESOLVED UPSTREAM | ||
Severity: | normal | CC: | arno |
Priority: | NOR | ||
Version: | unspecified | ||
Target Milestone: | --- | ||
Platform: | unspecified | ||
OS: | All | ||
Latest Commit: | Version Fixed In: | ||
Sentry Crash Report: | |||
Attachments: | C++ example with error |
Description
roland
2011-08-12 00:05:23 UTC
It works exactly as it's supposed to. First, the QFile constructor does NOT open the file for you. (I wonder where you got that from, certainly it doesn't say so in the Qt docs). Second, you're doing it wrong. See the following snippet to learn how to do it the right way: using System; using Qyoto; class MainClass { public static void Main(string[] args) { new QCoreApplication(args); // just for Qyoto initialization QFile file = new QFile("hello.txt"); file.Open((uint) QIODevice.OpenModeFlag.WriteOnly); QTextStream stream = new QTextStream(file); stream.Write("Hello World!"); file.Close(); } } That's what I love! Speak with great authority directly out rectal sphincter on a Friday without testing the actual case presented. Add one line to your "proof" and QFile is horribly busted. using System; using Qyoto; class MainClass { public static void Main(string[] args) { new QCoreApplication(args); // just for Qyoto initialization QFile file = new QFile("hello.txt"); file.SetTextModeEnabled( true); // notice this one line file.Open((uint) QIODevice.OpenModeFlag.WriteOnly); QTextStream stream = new QTextStream(file); stream.Write("Hello World!"); file.Close(); } } mcs test_snippet_1.cs -r:/usr/lib/mono/qyoto/qt-dotnet.dll roland@linux-c345:~/mega_mono_qt> mono test_snippet_1.exe QFile::open: File (hello.txt) already open QIODevice::write: ReadOnly device roland@linux-c345:~/mega_mono_qt> dir *.txt ls: cannot access *.txt: No such file or directory roland@linux-c345:~/mega_mono_qt> As to my using: Qyoto.Qyoto.GetCPPEnumValue("Qt.QIODevice","WriteOnly")); I did that because that is what the UI compiler generates in its code and that is what you find in examples. I agree your method is cleaner, but I could not find it documented, hence, one of the main reasons I'm writing this book. I hate it when I forget to log in first! That's what I love! Speak with great authority directly out rectal sphincter on a Friday without testing the actual case presented. It's always entertaining! Add one line to your "proof" and QFile is horribly busted. using System; using Qyoto; class MainClass { public static void Main(string[] args) { new QCoreApplication(args); // just for Qyoto initialization QFile file = new QFile("hello.txt"); file.SetTextModeEnabled( true); // ****notice this one line file.Open((uint) QIODevice.OpenModeFlag.WriteOnly); QTextStream stream = new QTextStream(file); stream.Write("Hello World!"); file.Close(); } } mcs test_snippet_1.cs -r:/usr/lib/mono/qyoto/qt-dotnet.dll roland@linux-c345:~/mega_mono_qt> mono test_snippet_1.exe QFile::open: File (hello.txt) already open QIODevice::write: ReadOnly device roland@linux-c345:~/mega_mono_qt> dir *.txt ls: cannot access *.txt: No such file or directory roland@linux-c345:~/mega_mono_qt> As to my using: Qyoto.Qyoto.GetCPPEnumValue("Qt.QIODevice","WriteOnly")); I did that because that is what the UI compiler generates in its code and that is what you find in examples. I agree your method is cleaner, but I could not find it documented, hence, one of the main reasons I'm writing this book. Yep, you're right. Setting this flag at that point will make it work incorrectly. However, this has nothing to do with the bindings. It's the same behaviour if you write it in plain C++/Qt (example attached). Solution: Call SetTextModeEnabled(true) *after* you've opened the file. Then it should work as expected. Regarding me not testing the actual case presented: I didn't do that because your example isn't self-contained. This has nothing to do with me being rude or anything. It's just that I can't compile and test your example code without modifying it (and thus maybe erasing the bug), which makes it *very* difficult to track down the actual bug. Sorry if I seemed rude or arrogant, that certainly hasn't been my intention. Created attachment 62786 [details]
C++ example with error
Send this bug up-stream then. A "set" method should only "set" a property, never actually OPEN a file. I will agree this is a baseline Qt bug, but the bug needs to be bubbled up from here since it was found here and we have complete examples that reproduce it consistently. Please "bubble-up" to Nokia. http://www.qtcentre.org/threads/20543-QFile-and-setTextMode so the issue seems to be known. Personally, I don't think this that this is actually a bug. The method only sets the QIODevice::Text flag for the open mode, which doesn't make sense if the file is not yet opened. Closing this bug now. If you still think it's a bug, please go ahead and report it on the Qt bugtracker. |