Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Qt6 #619

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open

Migrate to Qt6 #619

wants to merge 31 commits into from

Conversation

trevorRO
Copy link
Contributor

No description provided.

@trevorRO trevorRO changed the title find qt6 Migrate to Qt6 Feb 20, 2025
Comment on lines +29 to +31
foreach(QT_DEPENDENCY IN LISTS QT_DEPENDENCIES)
target_link_libraries(openbr "Qt6::${QT_DEPENDENCY}")
endforeach()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

target_link_libraries wants the Qt components as Qt6::Core where find_package just wants Core

@@ -33,7 +33,7 @@ static int partialCopy(const QString &string, char *buffer, int buffer_length)
{
const QByteArray byteArray = string.toLocal8Bit();

int copyLength = std::min(buffer_length-1, byteArray.size());
int copyLength = std::min(buffer_length-1, (int)byteArray.size());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qsizetype needs to cast to an int here for std::min

@@ -348,7 +348,7 @@ struct TemplateList : public QList<Template>
sum+=partitionSizes[i];
}

if (sum != first().size()) qFatal("Partition sizes %i do not span template matrices %i properly", sum, first().size());
if (sum != first().size()) qFatal("Partition sizes %i do not span template matrices %lli properly", sum, first().size());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deal with the warning: format specifies type 'int' but the argument has type 'qsizetype' (aka 'long long') [-Wformat]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qsizetype is signed, so maybe lld should be used everywhere

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think %lld and %lliare the same here but lld is used everywhere else so I'll switch it for consistency

Comment on lines +64 to +65
QStringList keys = this->localKeys();
keys.sort();
Copy link
Contributor Author

@trevorRO trevorRO Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qSort has been removed and recommended to use std::sort which is implemented in QStringList::sort()

@@ -1239,46 +1240,46 @@ QStringList br::Context::objects(const char *abstractions, const char *implement
QRegExp abstractionsRegExp(abstractions);
QRegExp implementationsRegExp(implementations);

if (abstractionsRegExp.exactMatch("Abbreviation"))
if (abstractionsRegExp.exactMatch("Abbreviation")) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suppresses warning: add explicit braces to avoid dangling else [-Wdangling-else]

Comment on lines -1629 to +1630
if (Globals->parallelism) futures.addFuture(QtConcurrent::run(this, &Distance::compareBlock, targets, queries, output, targetOffset, queryOffset));
if (Globals->parallelism) futures.addFuture(QtConcurrent::run(&Distance::compareBlock, this, targets, queries, output, targetOffset, queryOffset));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update to QConcurrent::run described here https://doc.qt.io/qt-6/concurrent-changes-qt6.html

Comment on lines 333 to 337
QList<int> allClusterIDs;
foreach(auto id, nextClusterIDs) {
if (!allClusterIDs.contains(id))
allClusterIDs.append(id);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fromList is no longer supported. Figured this was simply for removing duplicates so I just implemented that instead of relying on the QSet conversion to do it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recommend using QSet range constructor instead
QSet<int> set(list.begin(), list.end());

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure if there was any value to using QSet over manually removing the duplicates. QSet does feel cleaner but it didn't feel right to go from QList --> QSet --> QList

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, QSet feels better

Comment on lines 444 to 456
foreach(int clustID, truthVals.toSet()) {
int cnt = truthVals.count(clustID);
if (cnt > max) {
max = cnt;

QList<int> tempTruthVal = QList<int>();
foreach(int clustID, truthVals) {
if (!tempTruthVal.contains(clustID)) {
int cnt = truthVals.count(clustID);
if (cnt > max) {
max = cnt;
}

tempTruthVal.append(clustID);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another example of using QSet to remove duplicates. toSet no longer supported.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recommend using QSet range constructor instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, reverted

@@ -50,7 +50,7 @@ class evalOutput : public MatrixOutput
} else {
QFutureSynchronizer<float> futures;
for (int i=0; i<Globals->crossValidate; i++)
futures.addFuture(QtConcurrent::run(Evaluate, data, targetFiles, queryFiles, csv.arg(QString::number(i)), i));
futures.addFuture(QtConcurrent::run(qOverload<const cv::Mat &, const FileList &, const FileList &, const File &, int>(Evaluate), data, targetFiles, queryFiles, csv.arg(QString::number(i)), i));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that QtConcurrent::run does not support calling overloaded functions directly.

Comment on lines 333 to 337
QList<int> allClusterIDs;
foreach(auto id, nextClusterIDs) {
if (!allClusterIDs.contains(id))
allClusterIDs.append(id);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recommend using QSet range constructor instead
QSet<int> set(list.begin(), list.end());

Comment on lines 444 to 456
foreach(int clustID, truthVals.toSet()) {
int cnt = truthVals.count(clustID);
if (cnt > max) {
max = cnt;

QList<int> tempTruthVal = QList<int>();
foreach(int clustID, truthVals) {
if (!tempTruthVal.contains(clustID)) {
int cnt = truthVals.count(clustID);
if (cnt > max) {
max = cnt;
}

tempTruthVal.append(clustID);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recommend using QSet range constructor instead

@@ -348,7 +348,7 @@ struct TemplateList : public QList<Template>
sum+=partitionSizes[i];
}

if (sum != first().size()) qFatal("Partition sizes %i do not span template matrices %i properly", sum, first().size());
if (sum != first().size()) qFatal("Partition sizes %i do not span template matrices %lli properly", sum, first().size());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qsizetype is signed, so maybe lld should be used everywhere

@@ -58,7 +58,7 @@ class ebtsFormat : public Format
ok = true;
size = qFromBigEndian<quint32>((const uchar*)byteArray.mid(from,4).constData());
} else {
int index = byteArray.indexOf(QChar(0x1D), from);
int index = byteArray.indexOf("0x1D", from);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"\x1D" i think

Copy link
Contributor Author

@trevorRO trevorRO Feb 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we be able to drop the quotes and just put 0x1D

@@ -254,7 +254,7 @@ float Evaluate(const Mat &simmat, const Mat &mask, const File &csv, const QStrin
std::vector<float> impostors; impostors.reserve(comparisons.size());
QVector<int> firstGenuineReturns(simmat.rows, 0);

size_t falsePositives = 0, previousFalsePositives = 0;
size_t falsePositives = 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jklontz previousFalsePositives was unused. Just giving it visibility if it should be used.

if (variant.canConvert(QVariant::List)) return toString(qvariant_cast<QVariantList>(variant));
else if (variant.canConvert(QVariant::String)) return variant.toString();
else if (variant.canConvert(QVariant::PointF)) {
if (variant.canConvert(QMetaType(QMetaType::QVariantList))) return toString(qvariant_cast<QVariantList>(variant));
Copy link
Contributor Author

@trevorRO trevorRO Feb 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this version of canConvert is deprecated

Use canConvert(QMetaType(targetTypeId)) instead.

QMetaType()

QRegExp re(fileInfo.fileName());
re.setPatternSyntax(QRegExp::Wildcard);

QRegularExpression re = QRegularExpression(QRegularExpression::wildcardToRegularExpression(fileInfo.fileName()));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sold on this is correct. Need to test it in practice. Trying to follow the guide to port to Qt6 here: https://doc.qt.io/qt-6/qregexp.html#porting-to-qregularexpression

QStringList files;
foreach (const QString &fileName, dir.entryList(QDir::Files))
if (re.exactMatch(fileName))
if (re.match(fileName).hasMatch())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QRegExp::exactMatch() served two purposes: it exactly matched a regular expression against a subject string, and it implemented partial matching.

Need to figure out still which version of exactMatch we were looking for. Throughout this PR i've implemented the partial match solution

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -223,19 +223,17 @@ Neighborhood br::loadkNN(const QString &infile)
file.close();
int min_idx = INT_MAX;
int max_idx = -1;
int count = 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

count was unused

@trevorRO trevorRO marked this pull request as ready for review February 26, 2025 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants