Results 1 to 14 of 14

Thread: Character from argument disappears

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Character from argument disappears

    Quote Originally Posted by Pepe View Post
    Ok, that way it works, with the slash in front of the apostrophe.

    But the problem is that when the user double clicks on the file to open it, the filename is passed without the slash, so the file can't be opened!
    Have you actually tested that? It is probable that it was just the shell that ate your apostrophe. Double-clicking on a file might just work.
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

  2. #2
    Join Date
    Mar 2007
    Posts
    58
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Character from argument disappears

    Of course I tested it. Double-clicking doesn't open the file, the apostrophe is lost.

    But the strange thing, as I said before, is that if I enable the console (by adding "CONFIG += console" in the pro file) then the apostrophe is passed, and double-clicking works! Why?

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Character from argument disappears

    Probably one of Windows quirks. Do file names containing apostrophes can be opened by other (non-Microsoft origin) applications?

  4. #4
    Join Date
    Mar 2007
    Posts
    58
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Character from argument disappears

    Yes, other programs can open such files. I tested with a file named "that's_all.odt" which is opened by open office without problems. Also winamp can open a "that's_all.mp3" file.

    I've made a small program which can be used to test this problem. It simply displays the arguments in a QLabel:

    main.cpp:
    Qt Code:
    1. #include <QApplication>
    2. #include <QLabel>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. QLabel label;
    8.  
    9. for (int n= 0; n < a.argc(); n++) {
    10. QString argument = QString::fromLocal8Bit( a.argv()[n] );
    11. //QString argument = QString( a.argv()[n] );
    12. s += QString("arg # %1: <b>%2</b><br>").arg(n).arg(argument);
    13. }
    14. label.setText(s);
    15.  
    16. label.show();
    17. return a.exec();
    18. }
    To copy to clipboard, switch view to plain text mode 

    test.pro:
    Qt Code:
    1. SOURCES = main.cpp
    2.  
    3. #CONFIG += console
    To copy to clipboard, switch view to plain text mode 

    Running test.exe "that's all", displays as arg #1 "thats all".
    test.exe "that\'s all" properly displays "that's all".

    But right-clicking in the explorer on a filename with an apostrophe, and selecting to open it with test.exe displays the file without the apostrophe.

    Removing the QString::fromLocal8Bit() call doesn't make any difference.
    But uncommenting the #CONFIG += console line in the pro file magically fixes the problem.
    Now test.exe "that's all" displays "that's all".

    This is with Qt 4.3.0 in Windows. I haven't tested it with another version.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Character from argument disappears

    And what does QCoreApplication::arguments() return?

    BTW. Qt doesn't have anything to do with the problem. argc and argv is populated by the system.

  6. #6
    Join Date
    Mar 2007
    Posts
    58
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Character from argument disappears

    I'll check QCoreApplication::arguments() tomorrow (right now I'm on linux, so I can't test it).

    But what I did realize is that Qt 4.2.3 doesn't have this problem. A filename with an apostrophe does open in my application. So this seems to be a bug in Qt 4.3.0.

    Edit: Tested QCoreApplication::arguments(). It does the same, the apostrophe disappears
    Last edited by Pepe; 20th June 2007 at 01:07.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.