Results 1 to 3 of 3

Thread: Problem with relative paths when my app is lunched at windows startup

  1. #1
    Join Date
    Nov 2013
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Problem with relative paths when my app is lunched at windows startup

    Hi everybody,
    I created a reminder app that plays some mp3 files at specific times using QMediaPlayer an QMediaPlaylist. Those files are loaded in the playlist using relative paths. I added also the possibility to lunch the app by command line arguments at windows startup.
    the problem is when the app is lunched at startup ( HKLM\...\Run) the mp3 files are not loaded in the playlist BUT when i add the app .exe shortcut with the same command line arguments to the startup folder (AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup) mp3 files are loaded and everything is OK...
    Thanks for your help

    More informations:
    directory structure:
    struct.png

    main.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QApplication>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6.  
    7. QApplication a(argc, argv);
    8. mainwindow w;
    9. if (a.arguments().count() > 1)
    10. {
    11. QString arg1 = a.arguments().at(1);
    12. if(arg1==QString("/boot"))
    13. {
    14. w.startUp();
    15.  
    16. }
    17. }
    18. else
    19.  
    20. w.show();
    21.  
    22. return a.exec();
    To copy to clipboard, switch view to plain text mode 

    loading files into playList:
    Qt Code:
    1. {...}
    2. player = new QMediaPlayer(this);
    3. playList = new QMediaPlaylist();
    4. playList->addMedia(QUrl::fromLocalFile("media/sound.mp3"));
    5. playList->addMedia(QUrl::fromLocalFile("media/reminder.mp3"));
    6. playList->setPlaybackMode(QMediaPlaylist::CurrentItemOnce);
    7. player->setPlaylist(playList);
    8. {...}
    To copy to clipboard, switch view to plain text mode 

    startup function:
    Qt Code:
    1. void mainwindow::startUp()
    2. {
    3.  
    4. this->showMinimized();
    5. this->hide();
    6. trayIcon->show();
    7. }
    To copy to clipboard, switch view to plain text mode 


    Added after 1 47 minutes:


    Ok i solved the problem by using QCoreApplication::applicationDirPath () because when my app is started with windows the working directory changes to SysWOW64.
    Last edited by SimoLab; 2nd November 2013 at 23:43.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,734
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Problem with relative paths when my app is lunched at windows startup

    An option is to build them into your executable using the Qt resource system... then you simply cannot misplace them.

  3. #3
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,533
    Thanked 282 Times in 277 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with relative paths when my app is lunched at windows startup

    Read about QCoreApplication::applicationDirPath() and work with absolute paths.

Similar Threads

  1. Trouble with relative paths for files
    By N3wb in forum Qt Programming
    Replies: 2
    Last Post: 30th December 2010, 11:46
  2. Relative paths in Qt
    By drmath in forum Qt Programming
    Replies: 2
    Last Post: 30th June 2010, 16:50
  3. How to install a service in windows with automatic startup?
    By josecarlosmissias in forum Qt Programming
    Replies: 0
    Last Post: 11th December 2009, 17:01
  4. QDirModel, QCompleter, and Windows UNC paths
    By SnarlCat in forum Qt Programming
    Replies: 1
    Last Post: 17th April 2009, 09:27
  5. Show dialog application lunched as a process.
    By mourad in forum Qt Programming
    Replies: 0
    Last Post: 13th October 2008, 13:27

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.