в виджете qt это выглядит так
Код: Выделить всё
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include
#include
#include
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
// Dialog to choose an image
QString filePath = QFileDialog::getOpenFileName(this, "Open Image", "/storage/emulated/0", "Images (*.png *.xpm *.jpg)");
if (!filePath.isEmpty()) {
// Set the file path to the label for displaying path
ui->labelFilePath->setWordWrap(true);
ui->labelFilePath->setText(filePath);
QPixmap pixmap(filePath);
if (!pixmap.isNull()) {
ui->label->setPixmap(pixmap.scaled(ui->label->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
}
}
}
MainWindow::~MainWindow()
{
delete ui;
}
После этого я сделаю шоу тем, кому это понравится
Код: Выделить всё
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include \
#include \
#include \
MainWindow::MainWindow(QWidget \*parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui-\>setupUi(this);
}
MainWindow::\~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
QString filename = ui-\>filename-\>text();
// Tambahkan pengecekan panjang teks jika diperlukan
if (filename.length() < 1) {
QMessageBox::warning(this, "Input Error", "Please enter at least 1 characters for the filename.");
return;
}
//QString imagePath = "content://com.android.providers.downloads.documents/document/raw%3A%2Fstorage%2Femulated%2F0%2FDownload%2F"+filename+".jpg";
QString imagePath = "content://com.android.providers.downloads.documents/document/raw%3A%2Fstorage%2Femulated%2F0%2FDownload%2Fjoko.jpg";
//QString imagePath = "content://com.android.providers.media.documents/document/image%3A" + filename + ""; //19,20,21
//QString imagePath = "document/raw:/storage/emulated/0/Download/"+filename+".jpg";
QImage image(imagePath);
if (!image.isNull()) {
QImage scaledImage = image.scaled(ui->label->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
// Ubah QImage ke QPixmap
QPixmap pixmap = QPixmap::fromImage(scaledImage);
// Pastikan pixmap tidak null
if (!pixmap.isNull()) {
ui->label->setFixedSize(pixmap.size());
ui->label->setPixmap(pixmap);
ui->label->update();
} else {
QMessageBox::warning(this, "Load Error", "Failed to convert image.");
}
} else {
QMessageBox::warning(this, "Load Error", "The image could not be loaded. Please check the filename and file path.");
}
}
- он никогда не показывал введенный вами текст, если не 12 символов++
я уже напечатано, но ничего не отображается
12++ символов отображается - когда вы нажимаете кнопку, отображается только половина, вам нужно нажать отредактируйте строку, чтобы сделать ее полной
половину показывать
полной, когда вы синхронизируете lineedit
**
это установка
К вашему сведению Я создаю первую программу с помощью qtQuick Cmake, и в ней полный беспорядок (принудительное закрытие), и я делаю вторую программу с помощью QtQuick Qmake, и она работает нормально, путь в порядке, например (sdcard/Download/"+filename+".jpg ), но не работает с (Content://...)
Решение показать реальный путь к файлам, а не только content:// или обойти все это
Подробнее здесь: https://stackoverflow.com/questions/784 ... nternal-st
Мобильная версия