Results 1 to 5 of 5

Thread: QPixmap Error with Qt5

  1. #1
    Join Date
    Oct 2011
    Posts
    2
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    Windows Symbian S60

    Default QPixmap Error with Qt5

    I have migrated my solution from Qt4.8 to Qt5.0.1, after fixing the compilation and linking errors i got a run time error as follows

    QPixmap: Must construct a QApplication before a QPaintDevice


    error message.png

    taking in to consideration that the application was running before migrating to Qt5.0.1 and i am sure that i am constructing the QApplication in the first line in the main method as follows
    int main(argc, argv)
    {
    std::unique_ptr<QApplication> app(new QApplication(argc, argv));
    .
    .
    .
    .
    std::unique_ptr<MyMainForm> form(new MyMainForm(NULL));
    .
    .
    .

    return app.exec();
    }

    I tried to reproduce the problem in a smaller solution but it didn't appear, any suggestions will be welcomed.
    I debugged the ui_MyMainForm.h file and the code that causes the error is
    iconLabel->setPixmap(QPixmap(QString::fromUtf8(":/icons/icons/image.png")));

    working environment
    Qt5.0.1 with MSVisual studio 2010 x86
    Windows 7 x64
    Last edited by ahmed.khaled; 7th February 2013 at 21:31.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QPixmap Error with Qt5

    That's certainly a strange way to write a main() function. There is no need whatsoever to wrap either the QApplication instance or the MyMainForm instance in std::unique_ptr wrappers or to create them on the heap. If you construct your QApplication and MyMainForm on the stack, they are unique and will be destructed automatically when main() exits.

    Not only that, but the code you've provided won't compile (two declarations of "app") so how are we know what your code really looks like? The best we can do with this is to start throwing out random guesses as to why it fails. The fact that you tried a smaller solution means that you are doing something wrong in this one.

    Please use "CODE" tags when posting source code.

  3. #3
    Join Date
    Oct 2011
    Posts
    2
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    Windows Symbian S60

    Default Re: QPixmap Error with Qt5

    Thanks for the reply
    I am sorry for not checking the code i wrote before posting it
    the code is
    int main(argc, argv)
    {
    std::unique_ptr<QApplication> app(new QApplication(argc, argv));
    .
    .
    .
    .
    std::unique_ptr<MyMainForm> form(new MyMainForm(NULL));
    .
    .
    .

    return app.exec();
    }

    I also tried to create on the stack but in vain;
    int main(argc, argv)
    {
    QApplication app(argc, argv);
    .
    .
    .
    .
    MyMainForm form(NULL);
    .
    .
    .

    return app.exec();
    }
    still doesnt work
    I think you didnt notice that I told the project was runing well with Qt4.8 and the problem happened only after migration to 5.0.1, ireturned back to work with Qt4.8 and it worked.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QPixmap Error with Qt5

    You know, it's all the stuff where you have put ". . ." that probably makes all the difference. If you want help in solving a problem, you have to give us a little more than 4 lines of pseudo code.

    The fact that it works in 4.8 and not 5.0 is probably due to a bug fix or other change made in 5.0 that fixes the loophole in Qt that allowed your original code to work. It still doesn't mean your original code was correct, it just happens to work. And if you can't reproduce the problem in a smaller example, it definitely means your original code is incorrect.

    And please use CODE tags when posting source code. Click the "Go Advanced" button when making a post. You'll see a "#" tool button. Click it to insert the tags and paste your code in between.

  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: QPixmap Error with Qt5

    Your first example, using std::unique_ptr to wrap QApplication won't compile. The app object has no exec() function: you want the -> indirection operator. Neither example will compile because argc and argv have no type. To use your example we have to fix problems that are not related to the question. This is why we ask people to copy and paste actual compilable code.

    Quite aside from that, QPixmap is complaining and nothing you have shown us has anything to do with pixmaps.

    Got any classes being instantiated as global static instances? Any of those manipulate QPixmaps? These initialisation occur before main(). You could also be experiencing static initialization order issues.

Similar Threads

  1. QPixmap error message
    By Achuthan in forum Newbie
    Replies: 3
    Last Post: 5th June 2012, 22:18
  2. Replies: 1
    Last Post: 23rd September 2010, 18:12
  3. Replies: 1
    Last Post: 21st August 2008, 08:44
  4. Replies: 5
    Last Post: 9th April 2007, 15:26
  5. QPixmap::convertFromImage error (qt 4.1.1, g++ 3.3.2, Solaris SPARC 10)
    By freak in forum Installation and Deployment
    Replies: 3
    Last Post: 30th October 2006, 22:30

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.