c++ - 为什么我必须为 QFileDialog 指定父级

标签 c++ qt qt5

为什么我必须为 QFileDialog 指定父对象?

const QString& file_name = QFileDialog::getSaveFileName(
    0, // this
    "Export",
    QDir::currentPath(),
    "Excel files (*.xlsx)"
);

有什么意义?我可以将它设置为 0 吗?

最佳答案

是的,你可以将它设置为0。
QFileDialog继承了QDialogFrom Qt 5 QDialog documentation:

...A dialog is always a top-level widget, but if it has a parent, its default location is centered on top of the parent...

更新:第一条评论中有一个重要的补充。

关于c++ - 为什么我必须为 QFileDialog 指定父级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35272187/

相关文章:

c++ - 当我们在 qt 中关闭一个窗口时发出的信号是什么

C++ 和 Qt,如何在对象创建时运行构造函数或不同的函数来设置 Ui?

c++ - 使 QLabel 宽度独立于文本

postgresql - 在 PyQt5 中使用 PostgreSQL 的正确方法是什么

c++ - 生成不依赖于 Linux 的可执行文件

c++ - 如何将值初始化为 vector 中声明的对象?

qt - 使用 Qt 构建 64 位应用程序

c++ - 使用 SFML 和 Qt 窗口不显示

c++ - Eclipse CDT 与 Cygwin GCC : automatic discovery of symbols and paths

python - OS X : ld: library not found for -lstdc++