2016-07-27 279 views
2

我有以下的Qt代碼塊:QtCreator語義問題警告代碼永遠不會被執行

if(this->ueCommunicationsSocket()->bind(QHostAddress(data[0].toString()), 
             static_cast<quint16>(data[1].toInt())), 
             QAbstractSocket::ShareAddress) 
{ 
    qDebug() << Q_FUNC_INFO 
      << "TCP socket bind succesfull"; 
} 
else 
{ 
    qDebug() << Q_FUNC_INFO 
      << QString::number(this->ueCommunicationsSocket()->error()) 
      << this->ueCommunicationsSocket()->errorString(); // here i get semantic issue 
} // if 

和我得到語義發出警告代碼將永遠不會被執行。我知道這是一個愚蠢的錯誤,我準備得到downvote(s),但是,我找不到錯誤!這裏也是一個截圖: Qt Creator Semantic Issue

+0

你使用什麼編譯器?叮噹聲嗎? – demonplus

+0

不是,它是'gcc版本5.4.0 20160609(Ubuntu 5.4.0-6ubuntu1〜16.04.1)' – KernelPanic

+1

@KernelPanic是你在編譯時還是用QT_NO_DEBUG_OUTPUT定義?它看起來並不像其他QDebug似乎是警告,但我問,因爲我最近碰到了這個:http://lists.qt-project.org/pipermail/interest/2015-December/ 020171.html – Uflex

回答

1
if(this->ueCommunicationsSocket()->bind(QHostAddress(data[0].toString()), 
             static_cast<quint16>(data[1].toInt())), 
             QAbstractSocket::ShareAddress) 

if (/*something */, QAbstractSocket::ShareAddress) 

因爲AbstractSocket::SharedAddress0x1,這種情況用逗號操作!總是真,即else分公司將永遠不會被執行。

相關問題