Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Open an image in a window
I checked on google but I couldn't find a way so I decided to ask here.
Currently I am using this line of code:
Which just opens the image in windows image preview program.
What I want to do is open the picture in a window or a frame.
Hope you can help me, thank you.
andre last edited by
Create a QLabel without a parent widget, and set the image on that.
I guess I am doing something wrong? Because it does not display an image
QLabel * label_img = new QLabel (this);
label_img->setPixmap(QPixmap(QApplication::applicationDirPath()+"Primitives.png", 0, Qt::AutoColor));
andre last edited by
I think your path is not correct. Try outputting it using qDebug() and see what that yields. My guess is that you're missing a path separator between the directory and the file name, and that thus the file cannot be found, resulting in an empty image.
I feel so silly now xD I was missing " / " thank you =]
I am really amazed how great the Qt creator is, I am slowly moving away from Visual studio all together.
GentooXativa last edited by
We learn from errors, btw welcome to qt :D
Thank you GentooXativa,
I got another question if you don't mind, i would like to achieve same result but open a .pdf document is that possible or it just better to open it using adobe reader?
Qt doesn't have any built-in .pdf decoding/display classes that I'm aware of.
[quote author="mlong" date="1334681681"]Qt doesn't have any built-in .pdf decoding/display classes that I'm aware of.
Thanks for a quick reply
lgeyer last edited by
I know that there are Qt interfaces for "Poppler":http://people.freedesktop.org/~aacid/docs/qt4/ and "MuPDF":https://github.com/xiangxw/mupdf-qt/wiki. I haven't used both so far, but you might give them a try.
Using Poppler i get compile errors:
release/mainwindow.o:mainwindow.cpp:(.text+0x2e0): undefined reference to
_imp___ZN7Poppler8Document4loadERK7QStringRK10QByteArrayS6_' release/mainwindow.o:mainwindow.cpp:(.text+0x32f): undefined reference to_imp___ZNK7Poppler8Document8isLockedEv'
release/mainwindow.o:mainwindow.cpp:(.text+0x33c): undefined reference to `_imp___ZN7Poppler8DocumentD1Ev'
collect2: ld returned 1 exit status
mingw32-make.exe: *** [release\OpenGL.exe] Error 1
mingw32-make.exe: *** [release] Error 2
10:52:25: The process "E:\Qt_SDK\mingw\bin\mingw32-make.exe" exited with code 2.
Error while building project OpenGL Teaching Tool (target: Desktop)
When executing build step 'Make'
veeraps last edited by
Would you ensure that you have linked the libraries for Poppler?
Have you included them in your .PRO file under LIBS variable?
adlike last edited by
i think it depends on what kind of image format are you using. if you are trying tiff. you might as well use "tiff windows viewing app":http://www.rasteredge.com/how-to/vb-net-imaging/tiff-windows-viewer-create/ to "open a tiff image":http://www.rasteredge.com/how-to/vb-net-imaging/tiff-get-to-start/ in the pc. search on the web, you will find a lot.