使用qt creator + mingw + gdb進行qt專案開發時,應用q_assert進行斷言總是會出現問題: 斷言失敗,程式崩潰而不是停止;
採用自定義斷言能完美解決該問題(方法取自於國外論壇);
/**自定義斷言
*/#define iqs_assert 2
#if iqs_assert == 1
#define iqsassert q_assert
#elif iqs_assert == 2
#define iqsassert(cond) \
}#else
#define iqsassert(cond) {}
#endif
通過修改iqs_assert能切換斷言方式;
注: 上面的寫法只適用於除錯, 如果應用於發布版本,將出現未響應的狀態;
下面是我的修改方案:
/**自定義斷言
*/#ifdef qt_no_debug
#define debug_stop
#else
#define debug_stop
#endif
#define iqs_assert 2
#if iqs_assert == 1
#define iqsassert q_assert
#elif iqs_assert == 2
#define iqsassert(cond) \
}#else
#define iqsassert(cond) {}
#endif
通過qt_no_debug進行條件編譯,當編譯為release時,不進行軟中斷;
國外論壇:
Qt 自定義事件
最近做的專案,是用qt的完成的,在用到事件派發的時候,要用自己自定義的事件型別來滿足需要。具體就是按照qt的官方文件說明,做了乙個簡單的例子,以免忘記,就先寫下來儲存。首先有個customevent 類,繼承自qevent ifndef customevent h define customeven...
Qt 自定義事件
關於qt的自定義事件也是看了幾個大牛的部落格。總結下心得,如有錯誤請指出。一起成長。先給原始碼。也是第一次原創啊,不知道怎麼寫,呵呵。include include class mywidget public qwidget static const int mycustomeventtype 10...
QT 自定義委託
qt 中引入了經典的mvc結構,即模型 檢視 控制分離的結構,不過qt中只有mv沒有c,模型主要獲取資料,檢視主要複製模型的顯示,而委託只要是設定顯示的風格,在某一行某一列使用的不同的部件進行顯示,我在qt的qspinbox的歷程上加上了一點。通常委託都繼承qstyleditemdelegate和q...