Open an image in a window
-
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
@
void MainWindow::on_pushButton_clicked()
{
QLabel * label_img = new QLabel (this);
label_img->setWindowFlags(Qt::Window);
label_img->setPixmap(QPixmap(QApplication::applicationDirPath()+"Primitives.png", 0, Qt::AutoColor));
label_img->show();
}@ -
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.
-
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.
[/quote]
Thanks for a quick reply
-
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[1]: *** [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'
" -
Would you ensure that you have linked the libraries for Poppler?
Have you included them in your .PRO file under LIBS variable?
-
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.