qt qpixmap deprecated-error
This commit is contained in:
56
content/posts/2026/qt/qpixmap-error.md
Normal file
56
content/posts/2026/qt/qpixmap-error.md
Normal file
@@ -0,0 +1,56 @@
|
||||
---
|
||||
title: "🦗 Исправление ошибки Qpixmap Error"
|
||||
date: 2026-01-29T21:10:07+03:00
|
||||
draft: false
|
||||
tags: [tips, qt, cpp]
|
||||
---
|
||||
|
||||
Исправление ошибки:
|
||||
```text
|
||||
warning: ‘const QPixmap* QLabel::pixmap() const’ is deprecated: Use the other overload which returns QPixmap by-value
|
||||
```
|
||||
или
|
||||
```text
|
||||
error: conversion from ‘const QPixmap*’ to non-scalar type ‘QPixmap’ requested
|
||||
```
|
||||
если твой компилятор дебил!
|
||||
|
||||
**Причина ошибки:** В Qt 5.15+ метод `pixmap()` без аргументов возвращает
|
||||
**QPixmap** по значению, но если компилятор по какой-то причине выбирает устаревшую перегрузку,
|
||||
он пытается вернуть `const QPixmap*`.
|
||||
Использование явного типа `QPixmap` заставляет компилятор выбрать правильную перегрузку.
|
||||
|
||||
Однако указание явного типа у меня не сработало.
|
||||
|
||||
Информация о компиляторе:
|
||||
|
||||
```text
|
||||
Using built-in specs.
|
||||
COLLECT_GCC=gcc
|
||||
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/15.2.1/lto-wrapper
|
||||
Target: x86_64-pc-linux-gnu
|
||||
Configured with: /build/gcc/src/gcc/configure --enable-languages=ada,c,c++,d,fortran,go,lto,m2,objc,obj-c++,rust,cobol --enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues --with-build-config=bootstrap-lto --with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit --enable-cet=auto --enable-checking=release --enable-clocale=gnu --enable-default-pie --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object --enable-libstdcxx-backtrace --enable-link-serialization=1 --enable-linker-build-id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch --disable-werror
|
||||
Thread model: posix
|
||||
Supported LTO compression algorithms: zlib zstd
|
||||
gcc version 15.2.1 20260103 (GCC)
|
||||
```
|
||||
|
||||
Есть несколько решений.
|
||||
|
||||
|
||||
## Решение №1: Явное приведение типа
|
||||
|
||||
```cpp
|
||||
QPixmap currentPixmap = QPixmap(*pixmap());
|
||||
```
|
||||
|
||||
|
||||
## Решение №2: Использовать метод label()
|
||||
|
||||
```cpp
|
||||
QPixmap currentPixmap = this->pixmap(Qt::ReturnByValue);
|
||||
```
|
||||
|
||||
Ответ AI Google:
|
||||
|
||||

|
||||
Reference in New Issue
Block a user