本文整理汇总了C++中Q_LIKELY函数的典型用法代码示例。如果您正苦于以下问题:C++ Q_LIKELY函数的具体用法?C++ Q_LIKELY怎么用?C++ Q_LIKELY使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Q_LIKELY函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: metaObject
/*!
Inserts new record into the database, based on the current properties
of the object.
*/
bool TSqlObject::create()
{
// Sets the values of 'created_at', 'updated_at' or 'modified_at' properties
for (int i = metaObject()->propertyOffset(); i < metaObject()->propertyCount(); ++i) {
const char *propName = metaObject()->property(i).name();
QByteArray prop = QByteArray(propName).toLower();
if (prop == CreatedAt || prop == UpdatedAt || prop == ModifiedAt) {
setProperty(propName, QDateTime::currentDateTime());
} else if (prop == LockRevision) {
// Sets the default value of 'revision' property
setProperty(propName, 1); // 1 : default value
} else {
// do nothing
}
}
syncToSqlRecord();
QString autoValName;
QSqlRecord record = *this;
if (autoValueIndex() >= 0) {
autoValName = field(autoValueIndex()).name();
record.remove(autoValueIndex()); // not insert the value of auto-value field
}
QSqlDatabase &database = Tf::currentSqlDatabase(databaseId());
QString ins = database.driver()->sqlStatement(QSqlDriver::InsertStatement, tableName(), record, false);
if (Q_UNLIKELY(ins.isEmpty())) {
sqlError = QSqlError(QLatin1String("No fields to insert"),
QString(), QSqlError::StatementError);
tWarn("SQL statement error, no fields to insert");
return false;
}
TSqlQuery query(database);
bool ret = query.exec(ins);
sqlError = query.lastError();
if (Q_LIKELY(ret)) {
// Gets the last inserted value of auto-value field
if (autoValueIndex() >= 0) {
QVariant lastid = query.lastInsertId();
if (!lastid.isValid() && database.driverName().toUpper() == QLatin1String("QPSQL")) {
// For PostgreSQL without OIDS
ret = query.exec("SELECT LASTVAL()");
sqlError = query.lastError();
if (Q_LIKELY(ret)) {
lastid = query.getNextValue();
}
}
if (lastid.isValid()) {
QObject::setProperty(autoValName.toLatin1().constData(), lastid);
QSqlRecord::setValue(autoValueIndex(), lastid);
}
}
}
return ret;
}
示例2: QSslSocket
void QSslServer::incomingConnection(qintptr socket)
{
QSslSocket *pSslSocket = new QSslSocket();
if (Q_LIKELY(pSslSocket)) {
pSslSocket->setSslConfiguration(m_sslConfiguration);
if (Q_LIKELY(pSslSocket->setSocketDescriptor(socket)))
{
typedef void (QSslSocket::* sslErrorsSignal)(const QList<QSslError> &);
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 2)
connect(pSslSocket, &QSslSocket::peerVerifyError, this, &QSslServer::peerVerifyError);
connect(pSslSocket, &QSslSocket::encrypted, this, &QSslServer::newEncryptedConnection);
#else
connect(pSslSocket,SIGNAL(peerVerifyError(QSslError)), this, SIGNAL(peerVerifyError(QSslError)));
connect(pSslSocket, SIGNAL(sslErrors(QList<QSslError>)), this, SIGNAL(sslErrors(QList<QSslError>)));
connect(pSslSocket, SIGNAL(encrypted()), this, SIGNAL(newEncryptedConnection()));
#endif
addPendingConnection(pSslSocket);
pSslSocket->startServerEncryption();
}
else
{
delete pSslSocket;
}
}
}
示例3: QTcpServer
/*!
\internal
*/
void QWebSocketServerPrivate::init()
{
if (m_secureMode == NonSecureMode) {
m_pTcpServer = new QTcpServer(q_ptr);
if (Q_LIKELY(m_pTcpServer))
QObjectPrivate::connect(m_pTcpServer, &QTcpServer::newConnection,
this, &QWebSocketServerPrivate::onNewConnection);
else
qFatal("Could not allocate memory for tcp server.");
} else {
#ifndef QT_NO_SSL
QSslServer *pSslServer = new QSslServer(q_ptr);
m_pTcpServer = pSslServer;
if (Q_LIKELY(m_pTcpServer)) {
QObjectPrivate::connect(pSslServer, &QSslServer::newEncryptedConnection,
this, &QWebSocketServerPrivate::onNewConnection,
Qt::QueuedConnection);
QObject::connect(pSslServer, &QSslServer::peerVerifyError,
q_ptr, &QWebSocketServer::peerVerifyError);
QObject::connect(pSslServer, &QSslServer::sslErrors,
q_ptr, &QWebSocketServer::sslErrors);
QObject::connect(pSslServer, &QSslServer::preSharedKeyAuthenticationRequired,
q_ptr, &QWebSocketServer::preSharedKeyAuthenticationRequired);
}
#else
qFatal("SSL not supported on this platform.");
#endif
}
QObject::connect(m_pTcpServer, &QTcpServer::acceptError, q_ptr, &QWebSocketServer::acceptError);
}
示例4: onCloseConnection
/*!
\internal
*/
void QWebSocketServerPrivate::onCloseConnection()
{
if (Q_LIKELY(currentSender)) {
QTcpSocket *pTcpSocket = qobject_cast<QTcpSocket*>(currentSender->sender);
if (Q_LIKELY(pTcpSocket))
pTcpSocket->close();
}
}
示例5: ignoreSslErrors
/*!
* \internal
*/
void QWebSocketPrivate::ignoreSslErrors()
{
m_configuration.m_ignoreSslErrors = true;
if (Q_LIKELY(m_pSocket)) {
QSslSocket *pSslSocket = qobject_cast<QSslSocket *>(m_pSocket.data());
if (Q_LIKELY(pSslSocket))
pSslSocket->ignoreSslErrors();
}
}
示例6: Q_D
void QEventDispatcherBlackberry::wakeUp()
{
Q_D(QEventDispatcherBlackberry);
if (d->wakeUps.testAndSetAcquire(0, 1)) {
bps_event_t *event;
if (Q_LIKELY(bps_event_create(&event, bpsUnblockDomain, 0, 0, 0) == BPS_SUCCESS)) {
if (Q_LIKELY(bps_channel_push_event(d->bps_channel, event) == BPS_SUCCESS))
return;
else
bps_event_destroy(event);
}
qWarning("QEventDispatcherBlackberry: wakeUp failed");
}
}
示例7: min
void Arguments::copyToRegisters(ExecState* exec, Register* buffer, uint32_t maxSize)
{
if (Q_UNLIKELY(d->overrodeLength)) {
unsigned length = min(get(exec, exec->propertyNames().length).toUInt32(exec), maxSize);
for (unsigned i = 0; i < length; i++)
buffer[i] = get(exec, i);
return;
}
if (Q_LIKELY(!d->deletedArguments)) {
unsigned parametersLength = min(min(d->numParameters, d->numArguments), maxSize);
unsigned i = 0;
for (; i < parametersLength; ++i)
buffer[i] = d->registers[d->firstParameterIndex + i].jsValue();
for (; i < d->numArguments; ++i)
buffer[i] = d->extraArguments[i - d->numParameters].jsValue();
return;
}
unsigned parametersLength = min(min(d->numParameters, d->numArguments), maxSize);
unsigned i = 0;
for (; i < parametersLength; ++i) {
if (!d->deletedArguments[i])
buffer[i] = d->registers[d->firstParameterIndex + i].jsValue();
else
buffer[i] = get(exec, i);
}
for (; i < d->numArguments; ++i) {
if (!d->deletedArguments[i])
buffer[i] = d->extraArguments[i - d->numParameters].jsValue();
else
buffer[i] = get(exec, i);
}
}
示例8: select_all
void TabManager::select_all()
{
codeEditor *current=qobject_cast<codeEditor *>(currentWidget());
if(Q_LIKELY(current!=NULL))
current->selectAll();
}
示例9: paste
void TabManager::paste()
{
codeEditor *current=qobject_cast<codeEditor *>(currentWidget());
if(Q_LIKELY(current!=NULL))
current->paste();
}
示例10: dumpStringToFile
void FileAndDirectoryUtils::dumpStringToFile(QFile *f, QString &str) {
if (Q_LIKELY(f == NULL || str.length() <= minLengthToWrite)) {
return;
}
f->write(str.toLocal8Bit());
str.clear();
}
示例11: Q_D
// AspectThread
bool QPostman::shouldNotifyFrontend(const QSceneChangePtr &e)
{
Q_D(QPostman);
const QPropertyUpdatedChangePtr propertyChange = qSharedPointerDynamicCast<QPropertyUpdatedChange>(e);
if (Q_LIKELY(d->m_scene != nullptr) && !propertyChange.isNull()) {
const QScene::NodePropertyTrackData propertyTrackData
= d->m_scene->lookupNodePropertyTrackData(e->subjectId());
const QNode::PropertyTrackingMode trackMode = propertyTrackData.trackedPropertiesOverrides.value(QLatin1String(propertyChange->propertyName()),
propertyTrackData.defaultTrackMode);
switch (trackMode) {
case QNode::TrackAllValues:
return true;
case QNode::DontTrackValues:
return false;
case QNode::TrackFinalValues: {
const bool isIntermediate
= QPropertyUpdatedChangeBasePrivate::get(propertyChange.data())->m_isIntermediate;
return !isIntermediate;
}
default:
Q_UNREACHABLE();
return false;
}
}
return true;
}
示例12: Starts
/*!
\overload
Starts (or restarts) the timer with a \a msec milliseconds timeout and the
given \a timerType. See Qt::TimerType for information on the different
timer types.
\a obj will receive timer events.
\sa stop(), isActive(), QObject::timerEvent(), Qt::TimerType
*/
void QBasicTimer::start(int msec, Qt::TimerType timerType, QObject *obj)
{
QAbstractEventDispatcher *eventDispatcher = QAbstractEventDispatcher::instance();
if (Q_UNLIKELY(msec < 0)) {
qWarning("QBasicTimer::start: Timers cannot have negative timeouts");
return;
}
if (Q_UNLIKELY(!eventDispatcher)) {
qWarning("QBasicTimer::start: QBasicTimer can only be used with threads started with QThread");
return;
}
if (Q_UNLIKELY(obj && obj->thread() != eventDispatcher->thread())) {
qWarning("QBasicTimer::start: Timers cannot be started from another thread");
return;
}
if (id) {
if (Q_LIKELY(eventDispatcher->unregisterTimer(id)))
QAbstractEventDispatcherPrivate::releaseTimerId(id);
else
qWarning("QBasicTimer::start: Stopping previous timer failed. Possibly trying to stop from a different thread");
}
id = 0;
if (obj)
id = eventDispatcher->registerTimer(msec, timerType, obj);
}
示例13: writeFrame
/*!
\internal
*/
qint64 QWebSocketPrivate::writeFrame(const QByteArray &frame)
{
qint64 written = 0;
if (Q_LIKELY(m_pSocket))
written = m_pSocket->write(frame);
return written;
}
示例14: peerAddress
/*!
\internal
*/
QHostAddress QWebSocketPrivate::peerAddress() const
{
QHostAddress address;
if (Q_LIKELY(m_pSocket))
address = m_pSocket->peerAddress();
return address;
}
示例15: peerName
/*!
\internal
*/
QString QWebSocketPrivate::peerName() const
{
QString name;
if (Q_LIKELY(m_pSocket))
name = m_pSocket->peerName();
return name;
}