【发布时间】:2014-12-09 09:49:08
【问题描述】:
我正在尝试修改 UI。但是我不明白某些功能我无法修改 UI。例如:
// In this function there is nothing wrong.
void FindUser::on_btnBrowse_clicked()
{
browseFileName = QFileDialog::getOpenFileName(this, tr("Select Image"),
"file:///.1/", tr("Image Files (*.png *.jpg *.bmp)"));
qDebug() << browseFileName;
if(browseFileName != "")
{
ui->btnFindPerson->setEnabled(true);
selectedImg = QImage(browseFileName,"JPG");
ui->lblFindPersonImage->setPixmap(QPixmap::fromImage(selectedImg));
ui->lblFindPersonImage->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
ui->lblFindPersonImage->setScaledContents(true);
}
else
{
ui->btnFindPerson->setEnabled(false);
}
}
// However in this function when some operation done. Ui is not changing. I am sure that userFound() is working because I can see output of qDebug() without any problem. And also I add some Qlabel, and also they are not changing too.
void FindUser::userFound(QString imgFileName)
{
QStringList imgName = imgFileName.split(".");
qDebug() << imgName.at(0);
QString resultImgFileName = "/.1/Projects/MGFaceApp/bin/db/visible/" + imgName.at(0) + ".jpg";
QPixmap resultImgPixmap(resultImgFileName);
qDebug() << resultImgFileName;
ui->lblFindResultImage->setPixmap(resultImgPixmap);
ui->lblFindResultImage->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
ui->lblFindResultImage->setScaledContents(true);
}
// 这里是userFound(),它被调用的地方。
bool ImageProcess::imgIdentfiy(QImage img_ident)
{
....
....
....
if(identifyMember.identify(......))
{
....
if(matchedImgName != "")
{
FindUser findUserMember;
findUserMember.userFound(matchedImgName);
}
}
....
qDebug() << "Identify : DONE - DONE";
return true;
}
这里还有头文件:
namespace Ui {
class FindUser;
}
class FindUser : public QWidget
{
Q_OBJECT
public:
explicit FindUser(QWidget *parent = 0);
~FindUser();
void userFound(QString imgFileName);
private slots:
void on_btnBrowse_clicked();
void on_btnFindPerson_clicked();
private:
Ui::FindUser *ui;
QString browseFileName;
QImage selectedImg;
QString resultImgFileName;
};
我正在尝试查找我应该检查哪个选项,但我的尝试都没有解决这个问题。你有什么想法找到这个吗?
已编辑:这是我的实际代码。
【问题讨论】:
-
您确定实际调用了 userFound 方法吗? (它不是一个插槽)
-
@geoalgo,是的,我添加了 qDebug() 并查看控制台的输出。
-
我很惊讶地发现通过赋值运算符设置标签的文本是可行的。我会期待像
ui->lblPersonName->setText("...");这样的东西。这是哪个 Qt 版本? -
@goGud 你不能直接复制粘贴你的代码而不是再次输入吗?给我们一个minimal working example
-
当您的
if完成时,您的FindUser findUserMember将超出范围。您确定要在此处创建FindUser的新实例吗?我怀疑您已经在某处拥有FindUser的现有实例,您可以在屏幕上看到它。