QLabel->setPixmap not working?

1,188 views
Skip to first unread message

Levi Ribeiro

unread,
Nov 17, 2011, 12:32:55 PM11/17/11
to android-qt
Hi, I'm trying to put an image in QLabel, it worked fine in QT
Necessitas 0.2, but after the new release, it stopped working =/

Here's my code:

void MainWindow::on_pushButton_clicked()
{

static int i=2;

QDir local_path;

local_path.canonicalPath();
local_path.cdUp();
local_path.cdUp();
local_path.cdUp();
local_path.cdUp();
local_path.cd("sdcard");
local_path.cd("default");



QStringList file_list;
file_list = local_path.entryList();

int max_files;
max_files = local_path.count();


ui->label->setText(file_list[i]);
ui->label_2->setText(local_path.canonicalPath()); // using this to
view the path im in
ui->label_3->setPixmap(local_path.canonicalPath() + "/" +
file_list[i]);

i++;
if(i==max_files)
i = 2;
}


Can somebody tell me whats wrong?

Juan Manuel Sáez

unread,
Nov 17, 2011, 12:53:57 PM11/17/11
to andro...@googlegroups.com
Hello:

In the instruction:


   ui->label_3->setPixmap(local_path.canonicalPath() + "/" + file_list[i]);

it's compiling?

I think that you need to pass a QPixmap object:

   ui->label_3->setPixmap( QPixmap(local_path.canonicalPath() + "/" + file_list[i]) ) ;

I'm using QLabels for represent images and I have no problems.


Best regards
JMSaez

2011/11/17 Levi Ribeiro <levigr...@gmail.com>



--
______________________________________________________

Dr. Juan Manuel Sáez Martínez
Profesor Titular de Universidad
Departamento de Ciencia de la Computación e Inteligencia Artificial
Escuela Politécnica Superior. Universidad de Alicante
Teléfono: 965903900 ext 2752 Fax: 965903902
______________________________________________________

Levi Ribeiro

unread,
Nov 18, 2011, 10:53:19 AM11/18/11
to android-qt
I've tryed it on necessitas 0.2 and works, but in necessitas 0.3
doesnt. Can you share some sample code?

On 17 nov, 15:53, Juan Manuel Sáez <jms...@dccia.ua.es> wrote:
> Hello:
>
> In the instruction:
>
>    ui->label_3->setPixmap(local_path.canonicalPath() + "/" + file_list[i]);
>
> it's compiling?
>
> I think that you need to pass a QPixmap object:
>
>    ui->label_3->setPixmap( QPixmap(local_path.canonicalPath() + "/" +
> file_list[i]) ) ;
>
> I'm using QLabels for represent images and I have no problems.
>
> Best regards
> JMSaez
>
> 2011/11/17 Levi Ribeiro <levigribe...@gmail.com>

Levi Ribeiro

unread,
Nov 18, 2011, 10:54:19 AM11/18/11
to android-qt
Ahh, and it compiles, run, but the label shows nothing.

Juan Manuel Sáez

unread,
Nov 19, 2011, 10:49:52 AM11/19/11
to andro...@googlegroups.com
Hello Levi:

I have created a new project and I have only modified the API level to 10. Then, I modified the main.cpp file with that:

#include <QtGui/QApplication>
#include "mainwindow.h"

#include <QPixmap>
#include <QLabel>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QLabel *l = new QLabel();
    l->setPixmap(QPixmap("/data/tmp/test.jpg"));
    l->show();

    return a.exec();
}

Previously I have copied the test.jpg file to the device with:

adb push test.jpg /data/tmp

And that's all. It's working with necessitas R3. I haven't updated to the last R3.1 version, but I think that there's no modifications related with QLabel or QPixmap.

I think that your error is in the path that you are using.

Please revise the code that you sent some days ago because there's no prototype for:

label->setPixmap(QString);

You must send a QPixmap to this method.

then, the call:


ui->label_3->setPixmap(local_path.canonicalPath() + "/" + file_list[i]);

can't compile.

Hope it helps

JMSaez.

2011/11/18 Levi Ribeiro <levigr...@gmail.com>

Levi Ribeiro

unread,
Nov 22, 2011, 12:12:58 PM11/22/11
to android-qt
It stills doesnt work... Dont know why...

> 2011/11/18 Levi Ribeiro <levigribe...@gmail.com>

Reply all
Reply to author
Forward
0 new messages