Results 1 to 12 of 12

Thread: Problem with reffering to images (and another data files)

  1. #1
    Join Date
    Feb 2010
    Posts
    68
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Problem with reffering to images (and another data files)

    My Qt app folder looks like this:
    - bin
    - data

    In 'bin' there is the .exe file, and in 'data' there is a folder called 'icons' and there are a lot of icons in PNG format.
    All was great when I was running the exe file directly but when I started to run it using a shortcut on Desktop, there was no icons visible in the application.

    Here is the way I'm reffering to those icons:
    Qt Code:
    1. QAction *actionAddBox = new QAction(QIcon("../data/icons/addBox.png"),tr("Add new box (Ctrl+M)"),this);
    To copy to clipboard, switch view to plain text mode 

    What should I do?

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with reffering to images (and another data files)

    May be while starting the exe, its taking the desktop as the application directory. To confirm place data folder in desktop/../data and see what happens.
    To resolve you better include the png as a resource. You wont have to worry about the paths.
    Or make sure the relative paths are always there

  3. #3
    Join Date
    Feb 2010
    Posts
    68
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with reffering to images (and another data files)

    Ok, with a little help I've found the solution. It was a matter of "Current Directory" (or "Starting Directory") - every shortcut has something like this, It should be set to /bin folder in my case.

    Hey, but you've mentioned something about "including as a resource". How to do that? Can I include .dll files as well?

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with reffering to images (and another data files)


  5. The following user says thank you to aamer4yu for this useful post:

    kremuwa (9th March 2010)

  6. #5
    Join Date
    Feb 2010
    Posts
    68
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with reffering to images (and another data files)

    mingw32-make[1]: *** No rule to make target `application.qrc', needed by `release/qrc_application.cpp'. Stop.'
    I'm having such a message when I'm trying to build the project.

  7. #6
    Join Date
    Mar 2008
    Location
    France
    Posts
    149
    Thanks
    2
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with reffering to images (and another data files)

    You have to create a resource file (qrc extension) to embed your icon .

    For example, create and name this file myresource.qrc, containing the following:
    Qt Code:
    1. <RCC>
    2. <qresource >
    3. <file>:/Image/myimage.png</file>
    4. <file>:/Image/otherimage.png</file>
    5. </qresource>
    6. </RCC>
    To copy to clipboard, switch view to plain text mode 

    In your .pro file add the following: RESOURCES = myresource.qrc

    Then run qmake and make in order to add your png to your app.
    Last edited by toutarrive; 9th March 2010 at 12:32.

  8. #7
    Join Date
    Feb 2010
    Posts
    68
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with reffering to images (and another data files)

    Yes, I have done it like this but now I'm reiceving a message from post #6. Thx Anyway.

  9. #8
    Join Date
    Mar 2008
    Location
    France
    Posts
    149
    Thanks
    2
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with reffering to images (and another data files)

    What about if you run make clean ant then qmake and make ?

  10. #9
    Join Date
    Feb 2010
    Posts
    68
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with reffering to images (and another data files)

    Oh, I'm a really stupid guy. I'm currently (temporarily) on computer with Windows and with option "hide popular extensions" on. I created new file, named it 'application.qrc' and thought it's all right. But it wasn't because this file has actually .txt extension . Thank you for your effort, sorry for my stupidity and lacks in knowledge of english. Works perfectly now .

  11. #10
    Join Date
    Feb 2010
    Posts
    68
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with reffering to images (and another data files)

    Please, remove this post.
    Last edited by kremuwa; 10th March 2010 at 12:32.

  12. #11
    Join Date
    Feb 2010
    Posts
    68
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with reffering to images (and another data files)

    I've got another question.
    Is there any way to merge dll files needed by my app, put them as a one file to the catalogue with the executable and make it work?
    BTW. It would be even better if I could merge them with the executable itself. I tried doing so using the Qt Resource System, but i got messages like:
    cc1plus.exe: out of memory allocating 65536 bytes

  13. #12
    Join Date
    Mar 2008
    Location
    France
    Posts
    149
    Thanks
    2
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with reffering to images (and another data files)

    It would be even better if I could merge them with the executable itself
    You have to use (or build) the static version of the libraries needed by your app and then add the name of those libraries (*.lib extension) to the list of libraries processed by the linker.
    This process has got nothing to do with Qt resource files.

Similar Threads

  1. Loading images from resource files in webkit
    By redserpent7 in forum Qt Programming
    Replies: 1
    Last Post: 21st January 2015, 13:01
  2. OS X -- Using macdeployqt - where to put images and data subdirectories?
    By cometlinear in forum Installation and Deployment
    Replies: 1
    Last Post: 22nd February 2010, 21:48
  3. Creating images from sets of data.
    By maverick_pol in forum Qt Programming
    Replies: 5
    Last Post: 26th February 2008, 09:25
  4. Replies: 2
    Last Post: 19th December 2007, 14:02
  5. Replies: 3
    Last Post: 17th May 2007, 13:50

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.