PDA

View Full Version : QPixmap problem.



muny
4th November 2009, 17:23
I encounted compile phase problem.
The following code can be not compliled.
Is this C++ specification? Or, Qt specification?


/*use automatic variable for QPixmap instance*/
QPixmap p();//OK
p.loadFromData();//N.G. complile error.

/*use new operator for QPixmap instance.*/
QPixmap* p = new QPixmap();//OK
p->loadFromData();//OK.

caduel
4th November 2009, 18:56
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.

aamer4yu
5th November 2009, 07:51
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 :)

muny
5th November 2009, 17:11
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.




MyClass* mc = new MyClass();//This class get images(i.e. jpeg or png) from tcp/ip network.

/*use automatic variable for QPixmap instance*/
#if 0
QPixmap p();//OK
p.loadFromData(mc->getArray(), mc->getArraySize());//N.G. complile error.
QLabel* icon = new QLabel(p);
#endif

/*use new operator for QPixmap instance.
This code works.
*/
QPixmap* p = new QPixmap();//OK
p->loadFromData(mc->getArray(), mc->getArraySize());//OK.


QLabel* icon = new QLabel(*p);//



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).

muny
5th November 2009, 23:40
I am sorry. I have mistake in above code.
Following code is correct.



MyClass* mc = new MyClass();//This class get images(i.e. jpeg or png) from tcp/ip network.

/*use automatic variable for QPixmap instance*/
#if 0
QPixmap p();//OK
p.loadFromData(mc->getArray(), mc->getArraySize());//N.G. complile error.
QLabel* icon = new QLabel(this);
icon->setPixmap(p);
#endif

/*use new operator for QPixmap instance.
This code works.
*/
QPixmap* p = new QPixmap();//OK
p->loadFromData(mc->getArray(), mc->getArraySize());//OK.
QLabel* icon = new QLabel(this);
icon->setPixmap(*p);