Q_LIKELYQ_UNLIKELY 标记分支预测,缓存命中,提高执行效率。 Q_UNREACHABLE 执行到这里,程序会发生未定义的行为。常见的后果就是崩溃,用于标记永远不会执行到的语句,从而优化代码覆盖率。 Q_UNUSED 没有用到部分参数或对象时,编译器会发出警告,使用此宏减少警告。 qAbs 返回参数的绝对值 qMax 返回两
if (Q_UNLIKELY(!inst)) { if (!inst) { inst.reset(new NetServer()); } } return inst.data(); } 这段代码就是用的QSharedPointer 智能指针对单例指针进行维护,这样只要主进程还在,这个单例的指针就会一直保存在QSharedPointer内,就不会被析构了,除非你自己提供了一个析构的方法。发布...
task: %1, data: %2").arg(task).arg(data);QMessageBox::information(this,"tip",msg,QMessage...
#define DECLARE_SINGLETON(Class) \ Q_DISABLE_COPY(Class) \ public: \ static Class* Instance() \ { \ static QMutex mutex; \ static QScopedPointer<Class> inst; \ if (Q_UNLIKELY(!inst)) { \ mutex.lock(); \ if (!inst) inst.reset(new Class); \ mutex.unlock(); \ } \ return ins...
Q_UNLIKELY( expr) void Q_UNREACHABLE() Q_UNUSED( name) foreach( variable, container) forever qCritical(const char * message, ...) qDebug(const char * message, ...) qFatal(const char * message, ...) const char * qPrintable(const QString & str) qWarning(const char * message, .....
{ \staticQMutex mutex; \staticQScopedPointer<Class>inst; \if(Q_UNLIKELY(!inst)) { \ mutex.lock(); \if(!inst) inst.reset(newClass); \ mutex.unlock(); \ } \returninst.data(); \ } 然后声明的时候,填加一行这个宏: classMyClass ...
Q_UNLIKELY( expr) 空虚 Q_UNREACHABLE Q_UNUSED(姓名) foreach(变量,容器) 永远 qCritical(const char * message, ...) qDebug(const char * message, ...) qFatal(const char * message, ...) qInfo(const char * message, ...) qMove( x) const char * qPrintable(const QString& str) cons...
在文档的Core Internals小节,阐述了Qt Core模块是整个Qt框架的基础,其中QObject类构成了Qt对象模型(object model)的基础,是许多Qt类的父类。对象模型引入了许多机制,比如: 元对象系统(meta-object system) 属性系统(The Property System) 事件系统(event system) ...
} static bool qt_pixmap_thread_test() { if (Q_UNLIKELY(!QCoreApplication::instance())) { qFatal("QPixmap: Must construct a QGuiApplication before a QPixmap"); return false; } ... return true; } 哦,原来是这样。要创建QGuiApplication/QApplication之后才能去实例化QPaintDevice(Q...
5if (Q_UNLIKELY(!inst)) { 6 mutex.lock();7if (!inst) { 8 inst.reset(new MyClass);9 } 10 mutex.unlock();11 } 12return inst.data();13 } 既保证了线程安全⼜防⽌了内存泄漏,效率也没降低太多,简直完美。可惜每次都要重复这么⼏⾏实在⿇烦,于是写了⼀个模板类...