Results 1 to 5 of 5

Thread: QPixmap problem.

  1. #1
    Join Date
    Sep 2009
    Posts
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default QPixmap problem.

    I encounted compile phase problem.
    The following code can be not compliled.
    Is this C++ specification? Or, Qt specification?
    Qt Code:
    1. /*use automatic variable for QPixmap instance*/
    2. QPixmap p();//OK
    3. p.loadFromData();//N.G. complile error.
    4.  
    5. /*use new operator for QPixmap instance.*/
    6. QPixmap* p = new QPixmap();//OK
    7. p->loadFromData();//OK.
    To copy to clipboard, switch view to plain text mode 
    Last edited by muny; 4th November 2009 at 17:27.

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPixmap problem.

    QPixmap::loadFromData() takes 3 arguments, out of which the last 2 have defaults. So you have to specify at least one argument (the 'data') for it to compile.

    I don't really believe the second call did compile for you.

  3. #3
    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: QPixmap problem.

    Well well... this is not a Qt problem, rather C++ one !!
    QPixmap p();//OK
    This is declaring that you have a function p which returns QPixmap...its just a declration.

    So when you try to call p.loadFromData(); it will give you error.

    Just declare like -
    QPixmap p;

    and hope it will work

  4. #4
    Join Date
    Sep 2009
    Posts
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QPixmap problem.

    Hi, caduel. Thank you for your reply.
    I get a image byte-array and the array size via own class.
    Above code skipped own class for brief explanation.

    Qt Code:
    1. MyClass* mc = new MyClass();//This class get images(i.e. jpeg or png) from tcp/ip network.
    2.  
    3. /*use automatic variable for QPixmap instance*/
    4. #if 0
    5. QPixmap p();//OK
    6. p.loadFromData(mc->getArray(), mc->getArraySize());//N.G. complile error.
    7. QLabel* icon = new QLabel(p);
    8. #endif
    9.  
    10. /*use new operator for QPixmap instance.
    11.   This code works.
    12. */
    13. QPixmap* p = new QPixmap();//OK
    14. p->loadFromData(mc->getArray(), mc->getArraySize());//OK.
    15.  
    16.  
    17. QLabel* icon = new QLabel(*p);//
    To copy to clipboard, switch view to plain text mode 

    Hi, aamer4yu. Thank you for your reply.
    I do not have such function...
    But, I want to try your way : QPixmap p;
    Later date, I will report this try result. Thank you.

    In my enbedded environment, if possible, I want to avoid dynamic memory alloc(new and malloc).

  5. #5
    Join Date
    Sep 2009
    Posts
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QPixmap problem.

    I am sorry. I have mistake in above code.
    Following code is correct.

    Qt Code:
    1. MyClass* mc = new MyClass();//This class get images(i.e. jpeg or png) from tcp/ip network.
    2.  
    3. /*use automatic variable for QPixmap instance*/
    4. #if 0
    5. QPixmap p();//OK
    6. p.loadFromData(mc->getArray(), mc->getArraySize());//N.G. complile error.
    7. QLabel* icon = new QLabel(this);
    8. icon->setPixmap(p);
    9. #endif
    10.  
    11. /*use new operator for QPixmap instance.
    12.   This code works.
    13. */
    14. QPixmap* p = new QPixmap();//OK
    15. p->loadFromData(mc->getArray(), mc->getArraySize());//OK.
    16. QLabel* icon = new QLabel(this);
    17. icon->setPixmap(*p);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Zoom in Problem for QPixmap
    By jsmith in forum Qt Programming
    Replies: 1
    Last Post: 30th October 2009, 10:27
  2. Problem in using QHttp with QTimer
    By Ferdous in forum Newbie
    Replies: 2
    Last Post: 6th September 2008, 12:48
  3. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  4. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 08:47
  5. QPixmap and HBITMAP
    By ToddAtWSU in forum Qt Programming
    Replies: 1
    Last Post: 21st June 2006, 16:24

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.