Open an image in a window

  • Hey guys,

    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.

  • 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->setPixmap(QPixmap(QApplication::applicationDirPath()+"Primitives.png", 0, Qt::AutoColor));

  • 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?

  • Moderators

    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

  • I know that there are Qt interfaces for "Poppler": and "MuPDF": 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": to "open a tiff image": in the pc. search on the web, you will find a lot.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.