简体   繁体   English

子类化 QFileDialog

[英]Subclassing QFileDialog

I'd like to subclass QFileDialog to add a few parameters to it.我想继承 QFileDialog 以向它添加一些参数。 Basically, I'd like to add a few widgets that would specify how exactly the file should be saved.基本上,我想添加一些小部件来指定文件的保存方式。 What do I need to do for that?我需要为此做什么?

class ExportDialog : public QFileDialog
{
    Q_OBJECT

    public:
        ExportDialog( QWidget *parent ) : QFileDialog( parent )
        {
            setAcceptMode( QFileDialog::AcceptSave );
        }

        void AddParameterWidgets()
        {
            ...

I am getting errors like these:我收到这样的错误:

menu_file.cpp:756: undefined reference to `vtable for ExportDialog'

undefined reference to 'vtable for ExportDialog' can be caused by missing virtual functions. undefined reference to 'vtable for ExportDialog'可能是由于缺少虚函数造成的。

Often with Qt, it happens when you add a new file with a Q_OBJECT .通常在 Qt 中,当您添加带有Q_OBJECT的新文件时会发生这种情况。 If this is the case it can be solved by forcing qmake to re-run: "Right-click on your project > Run qmake" or using the menu "Build > Run qmake".如果是这种情况,可以通过强制qmake重新运行来解决:“右键单击您的项目 > 运行 qmake”或使用菜单“构建 > 运行 qmake”。

The root cause is that when you added the file the Q_OBJECT macro was not detected and therefore the file is not processed by the moc.根本原因是,当您添加文件时,未检测到 Q_OBJECT 宏,因此 moc 未处理该文件。 Running qmake will detect the Q_OBJECT macro.运行 qmake 将检测Q_OBJECT宏。

If this does not solve your issue, look into your code for functions declared in your class but not defined anywhere.如果这不能解决您的问题,请查看您的类中声明但未在任何地方定义的函数的代码。

If this still does not work, they you need to complete your question by providing a minimal reproducible example.如果这仍然不起作用,他们需要通过提供一个最小的可重复示例来完成您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM