Qt学习笔记 GtkDialog mapped without a transient parent. This is discouraged
编译环境:ubuntu-18.04.2Qt Creator 4.9.1 Based on Qt 5.12.3 (GCC 5.3.1 20160406 (Red Hat 5.3.1-6), 64 bit)QColorDialogQColor color = QColorDialog::getColor(Qt::red,this,tr("选择颜色"));报警:...
编译环境:
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("选择颜色"));
报警:
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的标准颜色对话框而不是操作系统的本机颜色对话框。
运行结果(没有报错):
QFileDialog
QString filename = QFileDialog::getOpenFileName(nullptr,tr("标题"),".","");
报警:
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;
}
运行结果(没有报错):
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.
换种方式
QFontDialog fontdialog;
fontdialog.setOption(QFontDialog::DontUseNativeDialog);
if(fontdialog.exec()== QDialog::Accepted )
{
QFont font = fontdialog.font();
qDebug() << font;
}
运行结果(没有报错):
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
所有评论(0)