gpt4 book ai didi

qt - 如何使用 Qt setWindowFilePath

转载 作者:行者123 更新时间:2023-12-04 06:48:09 27 4
gpt4 key购买 nike

我似乎无法让 setWindowFilePath 在我的任何项目中工作。该值已存储并可检索,但它从未显示在我的应用程序的标题栏中。它在我下载的示例应用程序中确实可以正常工作,但我找不到它们的不同之处。无论如何,这是我创建的一个简单的应用程序来演示这个问题。我粘贴了以下 3 个文件 mainwin.h、main.cpp 和 mainwin.cpp 中的代码。

有任何想法吗?我在 Windows 7 上使用 Qt 4.6.3 和 MS 编译器。

#ifndef MAINWIN_H
#define MAINWIN_H

#include <QMainWindow>

class mainwin : public QMainWindow
{
Q_OBJECT
public:
explicit mainwin(QWidget *parent = 0);

signals:

public slots:

};

#endif // MAINWIN_H

#include "mainwin.h"
#include <QApplication>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
app.setApplicationName("my test");
app.setOrganizationName("NTFMO");
mainwin window;
window.show();
return app.exec();
}

#include "mainwin.h"

mainwin::mainwin(QWidget *parent) :
QMainWindow(parent)
{
setWindowFilePath("C:\asdf.txt");

}

最佳答案

出于某种原因,setWindowFilePath()从 QMainWindow 的构造函数调用时似乎不起作用。但是您可以使用单发计时器:

class mainwin : public QMainWindow
{
...
private slots:
void setTitle();
}

mainwin::mainwin(QWidget *parent) :
QMainWindow(parent)
{
QTimer::singleShot(0, this, SLOT(setTitle()));
}

void mainwin::setTitle()
{
setWindowFilePath("C:\\asdf.txt");
}

并记住在文字路径中使用\\而不是\

关于qt - 如何使用 Qt setWindowFilePath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3493965/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com