Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi
I have wrote this code in Qt in Linux :

C++
#ifndef DIALOG_H
#define DIALOG_H

#include <QDialog>

namespace Ui {
class Dialog;
}

class Dialog : public QDialog
{
    Q_OBJECT
    
public:
    explicit Dialog(QWidget *parent = 0);
    ~Dialog();
    
private slots:
    void on_pushButton_clicked();

public slots:
    void load();

private:
    Ui::Dialog *ui;
};

#endif // DIALOG_H


C++
void Dialog::load(){

    QPixmap pixmap("/home/hor/1.jpg");
    ui->label->setPixmap(pixmap);
   // label.setPixmap(pixmap);
    ui->label->show();

}


And I have an jpg image in : /home/hor/1.jpg

But it doesn't work!!

Why?
Posted
Comments
jsolutions_uk 4-May-13 7:49am    
With jpg images, you need to make sure the jpeg imageformat plugin is loaded. I know on Windows it is found in (QTDIR)/plugins/imageformats/ I can't be sure where it is found on Linux off the top of my head. Usually I would place this file in the output folder for your project, under a plugins/imageformats/ folder. Hope that helps.

1 solution

Quote:
But it doesn't work!!

Is not pretty informative. You should elaborate.


The documentation[^] states:
If the file does not exist or is of an unknown format, the pixmap becomes a null pixmap

You didn't check for it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900