[SOLVED]convert const QImage & to QImage *
I want to use this function:
In my header file I created
and, in cpp file I initialized it
It is necessary because the size of image is not always 900×900. The size is taken from a file.
fromImage() function takes a parameter in const QImage & type, but in my program it must be QImage *, as I said above.
I used like this
this code does not give any build error, but during execution gives access violation error.
How can I use it, or how can convert?
9 replies
I think you could read directly the file you want in the QImage using something like this [doc.trolltech.com].
But why are you using a pointer to a QImage? And that code SHOULD give you an error, since the type passed to fromImage is “QImage **” which of course is not compatible with a “const QImage &”.
so the code must be then:
A reference requires an object not a pointer.
- class X* p; // is a pointer
To dereference a pointer to an object, you must put a star in front:
- class X {...};
- X* p;
- X obj;
- obj = *p;
- X& ref1 = obj; // correct, reference to obejct
- X& ref2 = *p; // correct, reference to dereferenced pointer
- X& ref3 = p; // error, as the reference is not a pointer!
- X*& ref4 = p; // correct, as the reference references a pointer to X --> modifying ref4 modifies p, not the object behind p!
yes, it is my fault.
I written this part as
It does not give build error, it gives error during execution “Access violation”
It show me, the error is in that part:
- {
- if (receiver != q) {
- for (int i = 0; i < receiver->d_func()->eventFilters.size(); ++i) { // in this part
- if (!obj)
- continue;
- if (obj->d_func()->threadData != receiver->d_func()->threadData) {
- qWarning("QCoreApplication: Object event filter cannot be in a different thread.");
- continue;
- }
- if (obj->eventFilter(receiver, event))
- return true;
- }
- }
- return false;
- }
Thanks guys,
the problem was not about the QImage.
I think it is an initialization problem, firstly I created the label and the image in the constructor,
after I filled the image and called the setPixmap function. It gave me error.
Now, I created the label and the image, and also called setPixmap function in the constructor.
After I filled the image and called setPixmap again. It works correctly.
You must log in to post a reply. Not a member yet? Register here!


