Results 1 to 6 of 6

Thread: Problems declaring global QIcons

  1. #1
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Problems declaring global QIcons

    Hi all, my application crashes when I make the following declarations of icons in the global space:

    Qt Code:
    1. static const QIcon IconeInicialFotoPetita("../icone.bmp");
    2. static const QIcon IconeLlibreObert("../llibreobert.png");
    3. static const QIcon IconeLlibreTancat("../llibretancat.png");
    4. static const QIcon IconeCarpetaOberta("../carpetaoberta.png");
    5. static const QIcon IconeCarpetaTancada("../carpetatancada.png");
    To copy to clipboard, switch view to plain text mode 

    But it doesn't crash if I just declare them as null icons:

    Qt Code:
    1. static const QIcon IconeInicialFotoPetita;
    2. static const QIcon IconeLlibreObert;
    3. static const QIcon IconeLlibreTancat;
    4. static const QIcon IconeCarpetaOberta;
    5. static const QIcon IconeCarpetaTancada;
    To copy to clipboard, switch view to plain text mode 

    Anybody could explain me why?

    Thanks.
    Last edited by SkripT; 7th March 2006 at 12:39.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problems declaring global QIcons

    Maybe they need a QApplication object? What does the backtrace tell you?

  3. #3
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problems declaring global QIcons

    Quote Originally Posted by wysota
    What does the backtrace tell you?
    The strange is that when the application crashes, it doesn't give any error message, simply it closes doing nothing. When I run it with gdb debugger it only says that the appplication have exited with value 1. Strange

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problems declaring global QIcons

    So does it crash or exit?

  5. #5
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problems declaring global QIcons

    It exits but it's really a crash

  6. #6
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems declaring global QIcons

    If QIcon is anything like QPixmap, it requires the use of resources from the window system. In Qt apps, you cannot use any window-system resources until you have created a Application object. Static objects are created initially at program startup before the main() funciton is even entered. That is why static Qt objects are (usually) a bad idea. Stick with your null QIcons and initialize them in an init() method that you call some time shortly after startup.
    Save yourself some pain. Learn C++ before learning Qt.

  7. The following user says thank you to Chicken Blood Machine for this useful post:

    SkripT (7th March 2006)

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.