为什么 setWindowFilePath 不起作用?插槽正在工作。窗口标题不会改变。 我的操作系统是Windows 7,Qt是用wchar_t支持编译的。
test::test(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);
QObject::connect(ui.pushButton, SIGNAL(clicked()), SLOT(Click()));
setWindowTitle("Title");
}
void test::Click()
{
setWindowFilePath("file.txt");
}
最佳答案
也许你的问题是你已经使用了 setWindowTitle()
使用前setWindowFilePath()
。来自 docs :
If the window title is set at any point, then the window title takes precedence and will be shown instead of the file path string.
编辑:我刚刚尝试使用 setWindowFilePath()
并注意到,只有在调用 show()
之后调用它,它才会生效。 。由于文档中没有提到这一点,所以它闻起来像一个错误......
编辑:好吧,如果不使用 setWindowTitle()
就无法工作。或调用setWindowFilePath()
调用show()
后,我不知道你的问题是什么。我做了一个工作示例,希望这可以帮助您找到问题:
#include <QApplication>
#include <QMainWindow>
#include <QPushButton>
class MyWindow : public QMainWindow
{
Q_OBJECT
public:
MyWindow()
{
QPushButton* b = new QPushButton("Click me", this);
connect(b, SIGNAL(clicked()), this, SLOT(click()));
}
private Q_SLOTS:
void click()
{
setWindowFilePath("file.txt");
}
};
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
MyWindow w;
w.show();
return app.exec();
}
#include "main.moc"
关于c++ - setWindowFilePath 在 Qt 中根本不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4624201/