How to display a QPixmap/QImage in QML?
-
@Wieland said in How to display a QPixmap/QImage in QML?:
qmlRegisterType<PixmapContainer>("io.qt.forum", 1, 0, "PixmapContainer");
qmlRegisterType<Backend>("io.qt.forum", 1, 0, "Backend");
qmlRegisterType<PixmapImage>("io.qt.forum", 1, 0, "PixmapImage");@Wieland Why did you register the backend & container objects? Why would you access such objects in the QML? Just being curious...
-
@Julian-Guarin You're right, registering those wasn't necessary here.
-
This is a very good example. I follow the code and it works exactly as I expected.
Thank you so much -
Hi, I just copied this example but I got some errors. in "backend.cpp" and "pixmapimage.cpp" . The errors are the same and:
error: undefined reference to `PixmapContainer::PixmapContainer(QObject*)'
What is the problem?
-
@yunus said in How to display a QPixmap/QImage in QML?:
What is the problem?
The problem is right there in the error message.
Where is PixmapContainer::PixmapContainer(QObject*) defined?
I guess you forgot to add the cpp file for PixmapContainer.Or change this line
explicit PixmapContainer(QObject *parent = 0);
to
explicit PixmapContainer(QObject *parent = 0) : QObject(parent) {}
-
@KroMignon It works, thank you!
-
@KroMignon said in How to display a QPixmap/QImage in QML?:
I found an alternative solution
So are you feeding that string to the "source" property of QML Image?
-
Thank a lot for your code example. Really appreciate.