Results 1 to 5 of 5

Thread: Can I make open files automaticly with my application

  1. #1
    Join Date
    Jan 2016
    Posts
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Can I make open files automaticly with my application

    Hi! I am making a music player and I want to make the mp3 files open my app with chosen file?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Can I make open files automaticly with my application

    If this is about registering your application with the system's type registry then this is not Qt related, you'll need to research the target platform's system for that.
    If this is about handling commandline arguments, then say so.

    Cheers,
    _

  3. #3
    Join Date
    Jan 2016
    Posts
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Can I make open files automaticly with my application

    Quote Originally Posted by anda_skoa View Post
    If this is about registering your application with the system's type registry then this is not Qt related, you'll need to research the target platform's system for that.
    If this is about handling commandline arguments, then say so.

    Cheers,
    _
    I don't know? How would qt understand where the file is (if I could get its location, I could handle it. I think) which I opened with my app?

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Can I make open files automaticly with my application

    Not Qt but every application. Read about commandline arguments in C/C++ applications.

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Can I make open files automaticly with my application

    How would qt understand where the file is
    If you are talking about something like double-clicking on an mp3 file name in Windows Explorer, and having Windows launch your Qt program to play the file, then you need to do two things:

    1 - Set up an association in Windows that associates files with the extension ".mp3" with your Qt program's EXE file. (There is certainly something similar in other operating systems).
    2 - In your Qt program's main() function, you have to look at the arguments to main(): "argc" is the count of the number of arguments on the command line, and is always at least 1. argv[] is an array of pointers to character strings. argv[0] is always the full command line (for example "MyProgram mysong.mp3"). If argc > 1, then argv[1] points to the first argument ("mysong.mp3"), and so forth.
    3 - If you find that argc > 1, then you extract argv[1], and pass it into the mp3 playing part of your program. If your program normally opens files interactively (i.e. using QFileDialog or something like that), then the method you'll want to call is probably the same one you would call when the user selects a file from the dialog. The string passed in as argv[1] is almost certainly the full path to the file, not just the filename, so you'll know exactly where the file lives.

    The association you set up in Windows (or whatever) takes care of starting your program for you, because that's how associations work. Once your program starts, you have to determine if t was started manually by the user with no filename (argc = 1) or by the operating system in response to a double-click on a filename (argc = 2).

Similar Threads

  1. how to make the QGraphicsScene resize automaticly
    By reboot in forum Qt Programming
    Replies: 3
    Last Post: 8th May 2017, 00:08
  2. Open odt files with Qt
    By Qiieha in forum Qt Programming
    Replies: 2
    Last Post: 21st April 2011, 09:29
  3. qca, qca-gnupg Not able to open files
    By sky in forum Newbie
    Replies: 1
    Last Post: 15th February 2011, 06:11
  4. How to open IGES files in Qt Application?
    By Shuchi Agrawal in forum Newbie
    Replies: 1
    Last Post: 21st February 2007, 01:06
  5. [Qt4.1]How to make links open browsers?
    By patcito in forum Qt Programming
    Replies: 8
    Last Post: 16th March 2006, 18:37

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.