Qt学习笔记 GtkDialog mapped without a transient parent. This is discouraged

 

编译环境:

ubuntu-18.04.2 

Qt Creator 4.9.1  Based on Qt 5.12.3 (GCC 5.3.1 20160406 (Red Hat 5.3.1-6), 64 bit)

 

QColorDialog

QColor color = QColorDialog::getColor(Qt::red,this,tr("选择颜色"));

Qt学习笔记 GtkDialog mapped without a transient parent. This is discouraged_第1张图片

报警:

Gtk-Message: 11:02:33.894: GtkDialog mapped without a transient parent. This is discouraged.

此报警也不会影响程序运行。

对于强迫症的人来说,可以采用其它方式来消除这个报警

    //QColor color = QColorDialog::getColor(Qt::red,this,tr("选择颜色"));
    QColor color(0,0,0);
    QColorDialog myColorDialog(color,this);
    //设置option
    myColorDialog.setOption(QColorDialog::DontUseNativeDialog);

    if( myColorDialog.exec() == QDialog::Accepted )
    {
        //获取当前选中的颜色
        color = myColorDialog.currentColor();
        qDebug() << color;
    }

myColorDialog.setOption(QColorDialog::DontUseNativeDialog);

使用Qt的标准颜色对话框而不是操作系统的本机颜色对话框。

运行结果(没有报错):

Qt学习笔记 GtkDialog mapped without a transient parent. This is discouraged_第2张图片

 

QFileDialog

 QString filename = QFileDialog::getOpenFileName(nullptr,tr("标题"),".","");

Qt学习笔记 GtkDialog mapped without a transient parent. This is discouraged_第3张图片

报警:

Gtk-Message: 11:02:33.894: GtkDialog mapped without a transient parent. This is discouraged.

换种方式

        //QString filename = QFileDialog::getOpenFileName(nullptr,tr("标题"),".","");
        QFileDialog filedialog;
        filedialog.setAcceptMode(QFileDialog::AcceptOpen);
        filedialog.setViewMode(QFileDialog::List);
        filedialog.setFileMode(QFileDialog::AnyFile);
        filedialog.setWindowTitle(tr("标题"));
        filedialog.setDefaultSuffix("txt");
        filedialog.setOption(QFileDialog::DontUseNativeDialog);
        if(filedialog.exec()==  QDialog::Accepted )
        {
            QStringList filePaths = filedialog.selectedFiles();
            QString filename =filePaths[0];
            qDebug() << filename;
        }

运行结果(没有报错):

Qt学习笔记 GtkDialog mapped without a transient parent. This is discouraged_第4张图片

 

QFontDialog

    bool ok;
    QFont font =QFontDialog::getFont(&ok);
    if(ok)
    {
        qDebug() << font;
    }

报警:

Gtk-Message: 11:02:33.894: GtkDialog mapped without a transient parent. This is discouraged.

Qt学习笔记 GtkDialog mapped without a transient parent. This is discouraged_第5张图片

换种方式

   QFontDialog fontdialog;
    fontdialog.setOption(QFontDialog::DontUseNativeDialog);
    if(fontdialog.exec()==  QDialog::Accepted )
    {
        QFont font = fontdialog.font();
        qDebug() << font;
    }

运行结果(没有报错):

 

Qt学习笔记 GtkDialog mapped without a transient parent. This is discouraged_第6张图片

你可能感兴趣的:(Qt)