Results 1 to 12 of 12

Thread: Problem in running QT Application

Hybrid View

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

    Default Re: Problem in running QT Application

    When a program fails to open a file that does exist, and you have specified a relative path, the odds are very good that the current working directory is not what you think it is (see QDir::currentPath()).

    You can obtain the location of the program executable using QCoreApplication::applicationDirPath() and build a path to the file that way.
    You can embed images in the executable using the resource system.

    It's also possible the image cannot load because a suitable image format plugin is not available (should not be the case with PNG).

  2. #2
    Join Date
    Sep 2011
    Posts
    27
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problem in running QT Application

    Now, I have taken the current dir path..still same no results yet. This is what i am doing:

    filename = QDir::currentPath();
    imgLoaded = img.load(filename +"/PICS/Car_New1.PNG" );

    if(true == imgLoaded)
    {
    _sPic.iId = this->bindTexture(img, GL_TEXTURE_2D, GL_RGB);
    _sPic.iHeight = img.height();
    _sPic.iWidth = img.width();
    }

    And, I have added this png in QRC file too its been embeded in Executables also but i dont know how to use this to map to our current context.

    Thanks!

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

    Default Re: Problem in running QT Application

    You seem to have missed the point. What is the value of currentPath()? Is it where you think it is? The current directory can be anywhere on the system and has nothing to do with the location of the program executable.

    The Qt Resource System

  4. #4
    Join Date
    Sep 2011
    Posts
    27
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problem in running QT Application

    I have seen some QT open gl Texture examples and I am also doing the same thing almost. But i dont understand why it doesn't work for me - may be I am doing some basic mistake which I am not able to uncover.

    How would I solve it? I dont have any clue about the problem!
    Would it going to help me if I place whole code?

    Thanks!

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

    Default Re: Problem in running QT Application

    I have already told you the most likely thing that is going wrong.

    Qt can only open the file if the file is where you tell Qt it is. If you are using a relative path then the file will be looked for relative to the current working directory of the running process, which can move around as the program runs. This is not generally the same as the directory containing the program executable. Unless you know the actual current working directory then you cannot know whether you are trying to open the file you think you are.

    You can use the Qt resource system to embed the image into your executable (if that meets your needs) so that it can always be found. I have already provided a linking detailing how this is used.

Similar Threads

  1. Replies: 4
    Last Post: 7th September 2011, 22:39
  2. Problem while running my qt application on OMAP3530.
    By vinod sharma in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 13th June 2011, 22:50
  3. problem running application in qvfb
    By maroonmoon in forum Installation and Deployment
    Replies: 0
    Last Post: 25th February 2010, 13:58
  4. getting problem in running qtopia home screen application
    By afgan_rajesh in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 31st January 2008, 07:01
  5. Running application on Mac OS X
    By munna in forum General Discussion
    Replies: 1
    Last Post: 19th April 2006, 20:10

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
  •  
Qt is a trademark of The Qt Company.