PDA

View Full Version : Duplicating and renaming a project breaks code



admkrk
25th February 2018, 01:05
<edit>I figured this out while I was composing this post, but figured I would post anyway, in case it is useful for someone else. The problem was that my kit was configured different, from the one the original project used. The original warning was somewhat correct, but instead of the compiler being wrong it was the Qt version. I had 5.2.1 selected instead of 5.8.0. </edit>

I need to re-purpose a project and I thought it would be easier to just strip out what I do not need than to rewrite what I do need. I copied the project folder to a new directory and renamed the project folder. I then renamed the .pro file and the target, then deleted the .pro.user file. I got a warning when I opened it Creator:

:-1: warning: "E:\QtA\Tools\mingw482_32\bin\g++.exe" is used by qmake, but "E:\QtA\Tools\mingw482_32\bin\g++.exe" is configured in the kit.
Please update your kit or choose a mkspec for qmake that matches your target environment better.
which I ignored since it did not make sense. Building the project was a different story. I eliminated half the warnings by copying the database folder, and others, to the build folder. I am not really concerned with the rest of the warnings, and the error is in a function that will get stripped, but I do not understand why warning free code suddenly has 30 warnings and an error preventing it from building. The error is:

error: invalid conversion from 'char' to 'const char*' [-fpermissive]
if(QStringRef(&link, 0, 1) == '/')
^
referenced from:

E:\Qt\Qt5.2.1\5.2.1\mingw48_32\include\QtCore\qstr ing.h:1345: error: initializing argument 1 of 'bool QStringRef::operator==(const char*) const' [-fpermissive]
inline QT_ASCII_CAST_WARN bool QStringRef::operator==(const char *s) const
The offending function:

void MainWindow::on_dataView_activated(const QModelIndex &index)
{
QString header = model->headerData(index.column(),
Qt::Horizontal).toString();

if(header == "Datasheet")
{
QString link = index.data(Qt::UserRole).toString();

if(QStringRef(&link, 0, 4) == "http")
QDesktopServices::openUrl(link);
else if(link == "")
return;
else
{
if(QStringRef(&link, 0, 1) == '/')
link.prepend(QDir::current().currentPath());

QDesktopServices::openUrl("file:///" + link);
}
}
}

Changing '/' to "/" fixed the error, but an identical one popped up in the model, which does not surprise me since it is basically the same code.

high_flyer
26th February 2018, 10:51
Thanks for sharing!