问题:
可能是分段错误的原因是什么?
或
如何更改背景图片。
我写道:
static QApplication *_app;
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
_app = &app;
...
app.setStyleSheet(ReadStyleSheet(STYLE_SHEET_WITH_BLUE_SCREEN));
...
}
// called with STYLE_SHEET_WITH_BLUE_SCREEN
void qtobeapp_setStyleSheet(int typeOfSheet)
{
syslog(LOG_DEBUG, "main: qtobeapp_setStyleSheet typeOfSheet[%d] _app[%p] 5", typeOfSheet, _app);
_app->setStyleSheet( ReadStyleSheet(typeOfSheet) );
syslog(LOG_DEBUG, "main: qtobeapp_setStyleSheet typeOfSheet[%d] _app[%p] 5", typeOfSheet, _app);
}
当我调用qtobeapp_setStyleSheet(STYLE_SHEET_WITH_BLUE_SCREEN)时;来自不同的线程
我会得到:
Jun 2 17:37:30 Viper user.debug QT_OBEAPP: main: qtobeapp_setStyleSheet typeOfSheet[1] _app[0xbffceab4] 5
Jun 2 17:37:30 Viper user.debug QT_OBEAPP: signal_handler: SIGNAL [11] caught. Sending PID: 0, UID: 11
Jun 2 17:37:30 Viper user.debug QT_OBEAPP: main: qtobeapp_setStyleSheet typeOfSheet[1] _app[0xbffceab4] 5
Jun 2 17:37:32 Viper user.err QT_OBEAPP: signal_handler: SIGNAL [11] caught. Stack trace size: 24
Jun 2 17:37:32 Viper user.err QT_OBEAPP: /afc/obe/QT_OBEAPP [0x1002697c]
Jun 2 17:37:32 Viper user.err QT_OBEAPP: [0x100374]
Jun 2 17:37:32 Viper user.err QT_OBEAPP: /lib/libQtGui.so.4 [0xea97498]
Jun 2 17:37:32 Viper user.err QT_OBEAPP: /lib/libQtGui.so.4 [0xea99060]
Jun 2 17:37:32 Viper user.err QT_OBEAPP: /lib/libQtGui.so.4 [0xea9d6a0]
Jun 2 17:37:32 Viper user.err QT_OBEAPP: /lib/libQtGui.so.4(_ZNK14QWidgetPrivate15paintBackgroundEP8QPainterRK7QRegioni+0x1a0) [0xe711808]
Jun 2 17:37:32 Viper user.err QT_OBEAPP: /lib/libQtGui.so.4(_ZN14QWidgetPrivate10drawWidgetEP12QPaintDeviceRK7QRegionRK6QPointiP8QPainterP19QWidgetBackingStore+0x3f0) [0xe71bb0c]
Jun 2 17:37:32 Viper user.err QT_OBEAPP: /lib/libQtGui.so.4 [0xe902a48]
Jun 2 17:37:32 Viper user.err QT_OBEAPP: /lib/libQtGui.so.4(_ZN14QWidgetPrivate16syncBackingStoreEv+0xa8) [0xe70c100]
Jun 2 17:37:32 Viper user.err QT_OBEAPP: /lib/libQtGui.so.4(_ZN7QWidget5eventEP6QEvent+0x7f4) [0xe71d7d4]
Jun 2 17:37:32 Viper user.err QT_OBEAPP: /lib/libQtGui.so.4(_ZN11QMainWindow5eventEP6QEvent+0x100) [0xeb78028]
Jun 2 17:37:32 Viper user.err QT_OBEAPP: /lib/libQtGui.so.4(_ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent+0xe4) [0xe6b8578]
Jun 2 17:37:32 Viper user.err QT_OBEAPP: /lib/libQtGui.so.4(_ZN12QApplication6notifyEP7QObjectP6QEvent+0x26c) [0xe6bf8cc]
Jun 2 17:37:32 Viper user.err QT_OBEAPP: /lib/libQtCore.so.4(_ZN16QCoreApplication14notifyInternalEP7QObjectP6QEvent+0xa8) [0xe20f4c8]
Jun 2 17:37:32 Viper user.err QT_OBEAPP: /lib/libQtCore.so.4(_ZN23QCoreApplicationPrivate16sendPostedEventsEP7QObjectiP11QThreadData+0x348) [0xe210ab0]
Jun 2 17:37:32 Viper user.err QT_OBEAPP: /lib/libQtCore.so.4(_ZN16QCoreApplication16sendPostedEventsEP7QObjecti+0x34) [0xe210c7c]
Jun 2 17:37:32 Viper user.err QT_OBEAPP: /lib/libQtGui.so.4 [0xe74c74c]
Jun 2 17:37:32 Viper user.err QT_OBEAPP: /lib/libQtCore.so.4(_ZN10QEventLoop13processEventsE6QFlagsINS_17ProcessEventsFlagEE+0x60) [0xe20e34c]
Jun 2 17:37:32 Viper user.err QT_OBEAPP: /lib/libQtCore.so.4(_ZN10QEventLoop4execE6QFlagsINS_17ProcessEventsFlagEE+0xdc) [0xe20e568]
Jun 2 17:37:32 Viper user.err QT_OBEAPP: /lib/libQtCore.so.4(_ZN16QCoreApplication4execEv+0xe4) [0xe210d80]
Jun 2 17:37:32 Viper user.err QT_OBEAPP: /lib/libQtGui.so.4(_ZN12QApplication4execEv+0x30) [0xe6b7924]
Jun 2 17:37:32 Viper user.err QT_OBEAPP: /afc/obe/QT_OBEAPP(main+0x380) [0x100267a8]
Jun 2 17:37:32 Viper user.err QT_OBEAPP: /lib/libc.so.6 [0xdf076a0]
Jun 2 17:37:32 Viper user.err QT_OBEAPP: /lib/libc.so.6 [0xdf07824]
没有调用qtobeapp_setStyleSheet(STYLE_SHEET_WITH_BLUE_SCREEN);,一切正常。
可能是分段错误的原因是什么?
或
如何更改背景图片。
谢谢
答案 0 :(得分:0)
Thank you all,
I used QMetaObject::invokeMethod to call QApplication::setStylesheet and it worked.
Exactly I called qtobeapp_setStyleSheet(int typeOfSheet) through QMetaObject::invokeMethod.