Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. qApp->addLibraryPath() doesn't work but PATH does (Windows, MinGW)

qApp->addLibraryPath() doesn't work but PATH does (Windows, MinGW)

Scheduled Pinned Locked Moved Solved Installation and Deployment
3 Posts 2 Posters 1.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • dflyD Offline
    dflyD Offline
    dfly
    wrote on last edited by
    #1

    Hi everyone. I successfully built Qt5.6 on Windows 10 using MinGW. Wasn't easy, but I fought through it.

    I also successfully got a hello world program to run. But I had to set PATH for it to pick up the DLLs, which isn't what I was hoping to do.

    I would love to hear if anyone has ideas on why the following fails at runtime:

    int main(int argc, char *argv[])
    {
    QCoreApplication qApp(argc, argv);

    qApp.addLibraryPath("C:\\Qt\\Qt56\\bin");
    qApp.addLibraryPath("C:\\MinGW\\mingw32\\bin");
    
    qDebug() << "Hello world!";
    
       return qApp.exec();
    

    }

    but

    int main(int argc, char *argv[])
    {
    QCoreApplication qApp(argc, argv);

    //qApp.addLibraryPath("C:\\Qt\\Qt56\\bin");
    //qApp.addLibraryPath("C:\\MinGW\\mingw32\\bin");
    
    qDebug() << "Hello world!";
    
       return qApp.exec();
    

    }

    runs successfully with:

    PATH=%PATH%;C:\Qt\Qt56\bin;C:\MinGW\mingw32\bin

    It should do the same thing, right?

    Obviously I have a workaround, but my goal was to read a file and load those dlls instead of setting the PATH, so this is not ideal for me. First world problems.

    Thank you!

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome.

      addLibraryPath is not for Qt core dlls. It's for (among other things) dynamically loaded libraries e.g. the various plugins. Core libraries are linked at compile time which means they are loaded before main() is even executed. If the dlls of those libs can't be found your app won't start and won't even get to the addLibraryPath code. Note that QCoreApplication is a class defined in one of these libraries so it needs to be already loaded to be instantiated.

      The usual deployment on Windows is to copy the needed dlls to the executable directory. Definitely don't rely on PATH or hardcoded absolute paths.

      1 Reply Last reply
      0
      • dflyD Offline
        dflyD Offline
        dfly
        wrote on last edited by
        #3

        That makes tons of sense, thank you. I hadn't even considered that it would need those libraries just to create the application object, but of course it does. Thanks for your quick reply!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved