Results 1 to 15 of 15

Thread: how to get input file name from the command line?

  1. #1
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Question how to get input file name from the command line?

    Hello. How can I get the file name passed to qt application from the command line? For example, I want to open some document when a user double clicks the file. If a file name contains spaces I receive it as separate words, therefore I can't distinguish "my file.txt" and "my file.txt" (many spaces).

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: how to get input file name from the command line?

    There no difference between how normal C/C++ main() takes arguments and how Qt Application main() takes. In fact in just the same.

    Prompt>executable.exe "long file name with space.txt"

    then
    arg[0] = "executable.exe" (C String)
    arg[1] = "long file name with space.txt" (C String)

  3. #3
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: how to get input file name from the command line?

    yes, but when open the file via double click the file name is not automatically quoted.

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: how to get input file name from the command line?

    What are you double clicking, the executable file or some data file?

  5. #5
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: how to get input file name from the command line?

    some data file, the same like you do when you open .doc file for example

  6. #6
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: how to get input file name from the command line?

    When you double click a file, it will be properly put in quotes and then supplied to the associated application (I am sure on windows it does)

    What is the platform you are using?

  7. #7
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: how to get input file name from the command line?

    Windows 7 x64. strange, i see it doesn't, because i receive argc = count of words, and each argv[i] is a word. The name is quoted if an application uses int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow), but qt uses main(int argc, char * argv[]) as the entry point

  8. #8
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: how to get input file name from the command line?

    Are you using Visual Stdio?

  9. #9
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: how to get input file name from the command line?

    yes, I am using Visual Studio 2008 SP1 along with Qt 4.7.2

  10. #10
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: how to get input file name from the command line?

    some data file, the same like you do when you open .doc file for example
    This is something you configure in windows (or what every system you are on).
    In windows, right click the data file -> properties -> open with.
    There you select the application that should be fed this file as a parameter and be opened.
    If you right click a *.doc file (or any other known to the system data file), you will see how it is done there.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  11. The following user says thank you to high_flyer for this useful post:

    mentalmushroom (25th May 2011)

  12. #11
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: how to get input file name from the command line?

    This is something you configure in windows (or what every system you are on).
    In windows, right click the data file -> properties -> open with.
    There you select the application that should be fed this file as a parameter and be opened.
    If you right click a *.doc file (or any other known to the system data file), you will see how it is done there.
    What are you talking about? I was not asking how to implement opening files via double click, but how can I get a file name that contains spaces.

  13. #12
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: how to get input file name from the command line?

    I was not asking how to implement opening files via double click, but how can I get a file name that contains spaces.
    Posts 4,5 and 6 are talking about double clicking a data file that should be openned by some application:
    What are you double clicking, the executable file or some data file?
    some data file, the same like you do when you open .doc file for example
    When you double click a file, it will be properly put in quotes and then supplied to the associated application (I am sure on windows it does)
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  14. #13
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: how to get input file name from the command line?

    He asked to understand what I want to do. Any ideas regarding getting file name?

  15. #14
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to get input file name from the command line?

    If you ask Windows for quotes, it'll give you quotes. If you don't ask for them, you will not get them by default.

    So, as suggested, copy an existing extension setup and it'll work.



    Note the quotes.
    Last edited by squidge; 25th May 2011 at 13:34.

  16. The following user says thank you to squidge for this useful post:

    mentalmushroom (25th May 2011)

  17. #15
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: how to get input file name from the command line?

    Ok, now I understand. Thank you.

Similar Threads

  1. How to compile from command line?
    By tonnot in forum Newbie
    Replies: 6
    Last Post: 15th March 2011, 14:55
  2. Replies: 2
    Last Post: 28th June 2009, 12:39
  3. QProcess and the command line
    By auba in forum Qt Programming
    Replies: 17
    Last Post: 27th May 2009, 10:39
  4. Printing to Command Line
    By seanmu13 in forum Qt Programming
    Replies: 3
    Last Post: 5th July 2007, 15:57
  5. Is there a command-line window in Qt4?
    By miaoliang in forum Qt Programming
    Replies: 2
    Last Post: 8th November 2006, 08:56

Tags for this Thread

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.