setWindowFilePath 在 Qt 中根本不起作用
为什么 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");
}
Why setWindowFilePath didn't work? Slot is working. The window title does not change.
My OS is Windows 7, Qt was compiled with wchar_t support.
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");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您的问题是您在使用
setWindowFilePath()
之前已经使用了setWindowTitle()
。来自文档:编辑:我刚刚尝试使用
setWindowFilePath()
,并注意到只有在调用show()之后调用它才会生效
。由于文档中没有提到这一点,所以它闻起来像一个错误...编辑:好吧,如果不使用
setWindowTitle()
或调用它就不起作用调用show()
后的setWindowFilePath()
,我不知道你的问题是什么。我做了一个工作示例,希望这可以帮助您找到问题:Maybe your problem is that you already used
setWindowTitle()
before usingsetWindowFilePath()
. From the docs:Edit: I just tried using
setWindowFilePath()
and noticed that it only takes effect if you call it after you callshow()
. Since this isn't mentioned in the docs, it smells like a bug...Edit: Well, if it doesn't work without using
setWindowTitle()
or with callingsetWindowFilePath()
after callingshow()
, I don't know what your problem is. I've made a working example so I hope this helps you in tracking down your problem: