Is there a "new" style for casting?
-
@saber said in Is there a "new" style for casting?:
@JonB
on every file "#endif " is added from first .
all the warnings was coming up after the update of qtcreator.see this
on the old version qt created this by it selfexplicit MainWindow(QWidget *parent = 0);
after update
should i replace the 0 with nullpointer on every file??
should it be a error in older version of compiler??
in my qmake i add that must have c++ 11 support .These are hints from clang on how to improve your code. You are not forced to do everything it says. You are seeing them now because the clang code model is default since Qt Creator 4.7. So previously you were using the old code model which did not offer these hints. That's all there is to it. If the code compiles fine (without warnings), you can ignore the hints.
However, it is a good idea to at least consider them, because these hints are (in 90% of cases) very good hints indeed.
In this case yes, I'd strongly recommend using
nullptr
rather than zero. It is an explicit, named value that makes it harder to make a mistake. -
I'm late to the party but just wanted to note Qt provides qFuzzyCompare and qFuzzyIsNull to compare double numbers for equality but you have to read the docs carefully before using them
-
@sierdzio said in Is there a "new" style for casting?:
@JonB said in Is there a "new" style for casting?:
at present the compiler/editor will be treating your file as though it did have that line at the end.
Whoa, really? Which compiler allows that?
For me (GCC) an unterminated ifdef is a hard error, compiler does not implicitly add it.The kind which generates a screenshot "Unterminated
#ifdef
" shown by the OP who says it's a warning but the app compiles fine.Now that you have said
Ignore it, then. The code model sometimes gets bogged down in ifdefs without reason.
I knew nothing about it being "clang". I took it that the OP had perhaps failed to get the last line of whatever he was fetching/copying (stranger things have been known to happen on this forum...). The OP should ignore my suggestion and stick with yours!
-
@saber said in Is there a "new" style for casting?:
add that enm
Please don't there is NOTHING to add to the enum! Simply remove the "default" inside the switch. Please read the link I posted more carefully, it is explained there.
-
Hi @saber,
the "Unterminated conditional directive" could be either QTCREATORBUG-18801 or QTCREATORBUG-20883
Regards,
-
i found new issue
QString DiskInfo::getDiskName() const { QDir blocks("/sys/block"); for (const QFileInfo entryInfo : blocks.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot)) { if (QFile::exists(QString("%1/device").arg(entryInfo.absoluteFilePath()))) { return entryInfo.baseName(); } } return QString(); }
here qt telling me
warning: loop variable 'entryInfo' of type 'const QFileInfo' creates a copy from type 'const QFileInfo'
-
@saber
In general, when you have a new question, post in a new thread. Since this thread is marked as "solved", people may not look.To your question: You loop through a list of QFileInfo objects. Your code copies the QFileInfo for every loop, which is unnecessary. Instead, you can use a const reference:
for (const QFileInfo& entryInfo : blocks.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot))
-
@Asperamanca thanks.it sloved.