Results 1 to 9 of 9

Thread: How can we create external Binary Resources in qt ?

  1. #1
    Join Date
    Aug 2011
    Location
    Bangalore, India
    Posts
    23
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows Symbian S60

    Default How can we create external Binary Resources in qt ?

    what is the format to create it? Does we can make custom resources with it?

  2. #2
    Join Date
    Aug 2011
    Location
    Bangalore, India
    Posts
    23
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows Symbian S60

    Default How can we create external Binary Resources in qt ?

    what is the format to create it? Does we can make custom resources with it?

  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: How can we create external Binary Resources in qt ?

    Do not cross post the same question in multiple places: that is bad form.
    See: How can we create external Binary Resources in qt

    Comment: This post was originally on a different thread before I merged both. Thus the post looks misplaces now... (Lykurg)
    Last edited by Lykurg; 1st December 2011 at 10:13.

  4. #4
    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: How can we create external Binary Resources in qt ?

    It is in the friendly manual under The Qt Resource System

  5. #5
    Join Date
    Aug 2011
    Location
    Bangalore, India
    Posts
    23
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows Symbian S60

    Default Re: How can we create external Binary Resources in qt ?

    Quote Originally Posted by ChrisW67 View Post
    It is in the friendly manual under The Qt Resource System
    i think you are talking about storing images only i want to store widget geometry, style and i want to access it when required. Do you know how can we do it?

  6. #6
    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: How can we create external Binary Resources in qt ?

    A typical use of the resource system is to store images but you can store any data you like in the resource and interpret it any way you like when you read it. Resources are read only, so if the problem you are trying solve involves saving settings between runs then you want QSettings or your own file format, which has nothing to do with resources.

  7. #7
    Join Date
    Aug 2011
    Location
    Bangalore, India
    Posts
    23
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows Symbian S60

    Default Re: How can we create external Binary Resources in qt ?

    Quote Originally Posted by ChrisW67 View Post
    A typical use of the resource system is to store images but you can store any data you like in the resource and interpret it any way you like when you read it. Resources are read only, so if the problem you are trying solve involves saving settings between runs then you want QSettings or your own file format, which has nothing to do with resources.
    Have you ever used .rc file in vc++. I want to make resources file something like that. Storing macro in .rc file and accessing it in program wherever used.

  8. #8
    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: How can we create external Binary Resources in qt ?

    Quote Originally Posted by pratik041 View Post
    Have you ever used .rc file in vc++.
    Yes.
    I want to make resources file something like that. Storing macro in .rc file and accessing it in program wherever used.
    You can, of course, use the Windows resource system on Windows.

    It's not clear what macros you are referring to. The macros that are associated with a Windows rc files are defined outside the rc file in a header file. Your C++ source code uses that header file to access those macro definitions. When you use those macros in conjunction with the Win32 API function that load reosurces, e.g. LoadCursor(), the Windows library fetch the relevant blob of the (compiled) resource data and return it. For example:
    Qt Code:
    1. // In resources.h
    2. #define IDC_TARGET 1000
    3.  
    4. // In resources.rc
    5. #include "resources.h"
    6. IDC_TARGET CURSOR "Target.cur"
    7.  
    8. // In some cpp file
    9. #include "resources.h"
    10. ...
    11. LoadCursor(NULL, IDC_TARGET);
    To copy to clipboard, switch view to plain text mode 

    Nothing is stopping you from doing something similar for a Qt resource file:
    Qt Code:
    1. // In resources.qrc
    2. <!DOCTYPE RCC><RCC version="1.0">
    3. <qresource>
    4. <file>icons/target.png>
    5. </qresource>
    6. </RCC>
    7. // In resources.h
    8. #define IDC_TARGET ":/icons/target.png"
    9. // In some cpp file
    10. #include "resource.h"
    11. ...
    12. QCursor cursor(QPixmap(IDC_TARGET));
    To copy to clipboard, switch view to plain text mode 
    or you can use the alias mechanism in the QRC file to provide a name that is independent of the included file name (so you can change the underlying file without changing your code):
    Qt Code:
    1. // In resources.qrc
    2. <!DOCTYPE RCC><RCC version="1.0">
    3. <qresource>
    4. <file alias="IDC_TARGET">icons/target.png>
    5. </qresource>
    6. </RCC>
    7. // In some cpp file
    8. QCursor cursor(QPixmap(":/IDC_TARGET"));
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Aug 2011
    Location
    Bangalore, India
    Posts
    23
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows Symbian S60

    Default Re: How can we create external Binary Resources in qt ?

    Quote Originally Posted by ChrisW67 View Post
    Yes.

    You can, of course, use the Windows resource system on Windows.

    It's not clear what macros you are referring to. The macros that are associated with a Windows rc files are defined outside the rc file in a header file. Your C++ source code uses that header file to access those macro definitions. When you use those macros in conjunction with the Win32 API function that load reosurces, e.g. LoadCursor(), the Windows library fetch the relevant blob of the (compiled) resource data and return it. For example:
    Qt Code:
    1. // In resources.h
    2. #define IDC_TARGET 1000
    3.  
    4. // In resources.rc
    5. #include "resources.h"
    6. IDC_TARGET CURSOR "Target.cur"
    7.  
    8. // In some cpp file
    9. #include "resources.h"
    10. ...
    11. LoadCursor(NULL, IDC_TARGET);
    To copy to clipboard, switch view to plain text mode 

    Nothing is stopping you from doing something similar for a Qt resource file:
    Qt Code:
    1. // In resources.qrc
    2. <!DOCTYPE RCC><RCC version="1.0">
    3. <qresource>
    4. <file>icons/target.png>
    5. </qresource>
    6. </RCC>
    7. // In resources.h
    8. #define IDC_TARGET ":/icons/target.png"
    9. // In some cpp file
    10. #include "resource.h"
    11. ...
    12. QCursor cursor(QPixmap(IDC_TARGET));
    To copy to clipboard, switch view to plain text mode 
    or you can use the alias mechanism in the QRC file to provide a name that is independent of the included file name (so you can change the underlying file without changing your code):
    Qt Code:
    1. // In resources.qrc
    2. <!DOCTYPE RCC><RCC version="1.0">
    3. <qresource>
    4. <file alias="IDC_TARGET">icons/target.png>
    5. </qresource>
    6. </RCC>
    7. // In some cpp file
    8. QCursor cursor(QPixmap(":/IDC_TARGET"));
    To copy to clipboard, switch view to plain text mode 
    Thank you it is now little bit clear but you are storing only image in qrc file. Can we store buttontext, style, location of widget in qrc file. If yes how we will write that ?
    Last edited by pratik041; 2nd December 2011 at 08:12. Reason: updated contents

Similar Threads

  1. Is it possible to add QT resources to a DLL?
    By cboles in forum Qt Programming
    Replies: 4
    Last Post: 17th January 2017, 01:12
  2. QWebView sometimes not loading external resources
    By complexgeek in forum Qt Programming
    Replies: 2
    Last Post: 6th June 2011, 03:37
  3. Replies: 1
    Last Post: 25th January 2010, 09:24
  4. create personalized binary without having to recompile
    By niko in forum General Programming
    Replies: 8
    Last Post: 6th October 2007, 13:20
  5. Replies: 3
    Last Post: 27th March 2007, 11:44

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.