c++ 样式错误 “Unknown property transition” /“Could not parse stylesheet of object 0xb88164f8”

解决办法

  1. 通过遍历所有的控件,
  • “Unknown property transition
  1. 打印出所有的控件地址,将地址 GPS 2>&1 log.log 输出到log日志中
  • “Could not parse stylesheet of object 0xb88164f8”
  1. 关键函数QString getWidgetHierarchy(QObject* widget) 获得所有的控件
#include <QApplication>
#include "gps_mainwindow.h"
#include <QTextCodec>
#include <QMessageBox>

#include <QStyleFactory>
#include "gps_protocal_test.h"
#include "global_define.h"
#if defined(Q_OS_UNIX)

#endif

#include "../goose/gps_gooseinimgr.h"


using namespace std;

// 辅助函数:递归获取控件的层级路径
QString getWidgetHierarchy(QObject* widget) {
    QStringList hierarchy;
    while (widget) {
        QString name = widget->objectName();
        if (name.isEmpty()) {
            name = widget->metaObject()->className();
        }
        hierarchy.prepend(name);
        widget = widget->parent();
    }
    return hierarchy.join(" -> ");
}


#include <QApplication>
#include <QWidget>
#include <QPointer>
#include <QDebug>
#include <QTextCodec>
#include <QMessageBox>
// 打印所有控件及其地址
void printAllWidgetAddresses() {
    foreach (QObject* obj, qApp->allWidgets()) {
        QWidget* widget = qobject_cast<QWidget*>(obj);
        if (widget) {
            qDebug() << "Widget Address:" << widget << "Class Name:" << widget->metaObject()->className();
        }
    }
}

int main(int argc, char* argv[])
{
	qputenv("QT_IM_MODULE", ("Qt5Input"));

	QApplication a(argc, argv);
//	writeLog("main");
	int ret;
#if defined(Q_OS_UNIX)
	//设置字符节
	a.setFont(QFont("simsun", 12));
	QTextCodec::setCodecForLocale(QTextCodec::codecForName("GBK"));			//路径名支持中文
#else
	QTextCodec* locale_codec = QTextCodec::codecForLocale();
	if (!locale_codec) {
		QMessageBox::critical(0, "启动失败", "取本地编码类型失败");
	}


#endif
	GPS_InitManager			InitManager;
	GPS_gooseIniMgr			initGooseini;
	GPS_serialManager		serial;
	GPS_bordcast			bordcast;
	GPS_protocal_test::loaddll("gpsbwjx");



	GPS_MainWindow w;
	w.show();
	// "Cleanlooks": 一个简单的、无修饰的控件样式,旨在提供一个统一的、现代的外观。
	//QApplication::setStyle(QStyleFactory::create("Fusion"));
    // 遍历所有控件,检查不支持的样式属性
    foreach (QObject* obj, qApp->allWidgets()) {
        QWidget* widget = qobject_cast<QWidget*>(obj);
        if (widget) {
            QString styleSheet = widget->styleSheet();
            if (styleSheet.contains("transition", Qt::CaseInsensitive)) {
                qDebug() << "Unsupported 'transition' property found in widget:";
                qDebug() << "Widget Hierarchy:" << getWidgetHierarchy(widget);
                qDebug() << "StyleSheet:" << styleSheet;
            }
        }
    }


	
 // 记录所有控件的地址
    printAllWidgetAddresses();

    // 记录出错的控件地址列表
    QList<QPointer<QWidget>> problematicWidgets;

    // 假设你已经确定了有问题的控件地址,可以在这里添加它们
    // 但要确保控件的地址是有效的,或者通过其他方式获取控件对象
    foreach (QObject* obj, qApp->allWidgets()) {
        QWidget* widget = qobject_cast<QWidget*>(obj);
        if (widget) {
            qDebug() << "Checking widget at address:" << widget;

            // 添加到 problematicWidgets 列表
            problematicWidgets.append(QPointer<QWidget>(widget));
        }
    }

    // 遍历所有控件,检查并打印与出错控件地址匹配的控件信息
    foreach (QObject* obj, qApp->allWidgets()) {
        QWidget* widget = qobject_cast<QWidget*>(obj);
        if (widget) {
            QString styleSheet = widget->styleSheet();
            qDebug() << "Checking widget at address:" << widget;

            // 检查控件地址是否在出错控件地址列表中
            if (problematicWidgets.contains(QPointer<QWidget>(widget))) {
                qDebug() << "Found problematic widget!";
                qDebug() << "Widget Type:" << widget->metaObject()->className();
                qDebug() << "Widget Address:" << widget;
                qDebug() << "Widget Name:" << widget->objectName();
                qDebug() << "Widget Hierarchy:" << getWidgetHierarchy(widget);
                qDebug() << "StyleSheet:" << styleSheet;
                
                // 输出控件的父控件信息
                if (widget->parent()) {
                    qDebug() << "Parent Widget:" << widget->parent()->metaObject()->className();
                    qDebug() << "Parent Object Address:" << widget->parent();
                }
            }
        }
    }








	a.setWindowIcon(QIcon("://Resources/sign.png")); //设置系统logo图标 cyx20160513
	ret = a.exec();

	return  ret;

}

posted @ 2024-12-11 11:32  苏念雨  阅读(220)  评论(0)    收藏  举报