[Interest] Image on QLabel doesn't show at all
Henry Skoglund
henry at tungware.com
Sat Dec 8 20:13:15 CET 2018
On 2018-12-08 18:23, Tamás Nagy wrote:
> Hi,
>
> pixmap = new QPixmap(imageUrl.toString());
> ui->imageLabel->setGeometry(QRect(QPoint(0,0), QPoint(pixmap->width(),
> pixmap->height()) ));
> ui->imageLabel->setPixmap(*pixmap);
> ui->imageLabel->setStyleSheet("background-image: url(" +
> imageUrl.toString() + ")");
> ui->imageLabel->update();
> ui->imageLabel->show();
>
> My image is C:\untitled.bmp
>
> I also have a second error: my signal is not found. It always tells me:
>
> 18:18:07: Debugging starts
> QMetaObject::connectSlotsByName: No matching signal for
on_graphics_changed()
> QObject::connect: No such signal
> MainWindow::MainWindow::graphicsChanged() in
> ..\untitled\mainwindow.cpp:11
> QObject::connect: (sender name: 'MainWindow')
> QObject::connect: (receiver name: 'MainWindow')
>
..
..
Hi, the 1st error is because you're doing a simple
imageUrl.toString() which returns % chars instead of backslashes, this
confuses QPixmap's constructor. To give QPixmap Windows-style filenames,
try:
pixmap = new QPixmap(imageUrl.toString(QUrl::PreferLocalFile));
And for making C:\untitled.bmp show up, try lose/commenting away that
->setStyleSheet() call, setPixmap(*pixmap); should suffice.
The 2nd error is actually a warning and then an error, the warning is
from setupUI() which sees your slot name on_graphics_changed(). Slot
names beginning with "on_" are kind of reserved, see more for example
here:
https://linux.m2osw.com/qtwarning-qmetaobjectconnectslotsbyname-no-matching-signal-onsomethingevent
And that 2nd error is most likely because on your line 11 in your
mainwindow.cpp (which I **cannot see** so I'm guessing :-) you wrote:
connect(this,SIGNAL(MainWindow::graphicsChanged()),this,SLOT(on_graphics_changed()));
Try change to
connect(this,SIGNAL(graphicsChanged()),this,SLOT(on_graphics_changed()));
Rgrds Henry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20181208/ed270846/attachment.html>
More information about the Interest
mailing list