Results 1 to 14 of 14

Thread: Character from argument disappears

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

    Default Character from argument disappears

    Using Qt 4.3 on Windows XP.

    If I pass to my application from command line a filename (or any text) which contains the character ' (apostrophe), that character disappears. Example: "hello'goodbye" turns into "hellogoodbye".

    The code I use is something like this:

    Qt Code:
    1. QApplication a( argc, argv );
    2. QString argument = QString::fromLocal8Bit( a.argv()[1] )
    To copy to clipboard, switch view to plain text mode 

    The same code on Linux with Qt 4.2.3 works ok, no character missing.

    Am I doing something wrong? Or is it a bug?

  2. #2
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Character from argument disappears

    Quote Originally Posted by Pepe View Post
    Using Qt 4.3 on Windows XP.
    If I pass to my application from command line a filename (or any text) which contains the
    Qt Code:
    1. QApplication a( argc, argv );
    2. QString argument = QString::fromLocal8Bit( a.argv()[1] )
    To copy to clipboard, switch view to plain text mode 

    if you follow only the source code from http://wiki.qtcentre.org/index.php?t...Mac_OSX_Finder QEvent::FileOpen
    !not the xml is work on window & mac & linux ... minimal hack and work on my Xfce 4 manager...

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

    Default Re: Character from argument disappears

    Quote Originally Posted by Pepe View Post
    Using Qt 4.3 on Windows XP.

    If I pass to my application from command line a filename (or any text) which contains the character ' (apostrophe), that character disappears. Example: "hello'goodbye" turns into "hellogoodbye".
    The shell probably eats up your apostrophe. Try surrounding the whole argument with quotes, like:

    myapplication.exe "hello'goodbye"

  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

    No, it doesn't work with or without quotes, the apostrophe is still missing.

    But I've just found out something: if I enable the console ("CONFIG += console" in the pro file) then the problem fixes, the filename is read ok. But I can't leave the console, it's ugly (when the user open the application, a console opens too).

    A Qt bug?
    Last edited by Pepe; 19th June 2007 at 02:50.

  5. #5
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Character from argument disappears

    As wysota already mentioned - the shell eats the apostrophe -> you have to quote it.
    Qt Code:
    1. myApp.exe hello\'goodbye
    To copy to clipboard, switch view to plain text mode 

  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

    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!

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

    Default Re: Character from argument disappears

    Blaim the shell Using quotes should help as well, I don't know why it didn't... Are you sure you used them correctly?

  8. #8
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Character from argument disappears

    The quotes don't help here - just tested it out... really strange

  9. #9
    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

  10. #10
    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?

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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?

  12. #12
    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.

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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.

  14. #14
    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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.