I Need Some Help With QtConcurrent On Mac
-
Hello,
I have a Windows program that I am trying to port over to MacOS, however I am having some trouble with QtConcurrent. Here is my code:
void MainWindow::on_pushButton_prepareChecksum01_clicked() { if(ui->radioButton_useTree01->isChecked()) { m_selectedFiles01.clear(); m_selectedDirectories01.clear(); m_checkProxy->checkedState()->checkedLeafSourceModelIndexes(m_selectedFiles01); m_checkProxy->checkedState()->checkedBranchSourceModelIndexes(m_selectedDirectories01); if (m_selectedFiles01.isEmpty() && m_selectedDirectories01.isEmpty()) { QMessageBox::information(this, "Nothing Is Selected", "No files or directories are selected. Please select a file or directory."); return; } prepareChecksumDisplay01(); QGuiApplication::setOverrideCursor(Qt::WaitCursor); m_prepareForChecksum01 = QtConcurrent::map(this, &MainWindow::treeChecksum01); m_watcher02.setFuture(m_prepareForChecksum01); } if(ui->radioButton_useBrowse01->isChecked()) { if (m_browsedDirs01.isEmpty() && m_browsedFiles01.isEmpty()) { QMessageBox::information(this, "Nothing Is Selected", "No directories or files have been added. Please add a directory or file."); return; } prepareChecksumDisplay01(); QGuiApplication::setOverrideCursor(Qt::WaitCursor); m_prepareForChecksum01 = QtConcurrent::map(this, &MainWindow::browseChecksum01); m_watcher02.setFuture(m_prepareForChecksum01); } }
On Windows I was able to use QtConcurrent::run, but this gives me an error on MacOS. Currently, the error is:
/Users/crv/Documents/Programming/C++/Qt/Checksum1/Checksum1-V1.0-master/mainwindow.cpp:552: error: member reference type 'MainWindow *' is a pointer; did you mean to use '->'?
I have tried using this->MainWindow::treeChecksum01 and ->treeChecksum01, but both won't compile. Any help would be appreciated. I am using a 2023 MacBook Pro with the latest LTS version of Qt.
-
Hello,
I have a Windows program that I am trying to port over to MacOS, however I am having some trouble with QtConcurrent. Here is my code:
void MainWindow::on_pushButton_prepareChecksum01_clicked() { if(ui->radioButton_useTree01->isChecked()) { m_selectedFiles01.clear(); m_selectedDirectories01.clear(); m_checkProxy->checkedState()->checkedLeafSourceModelIndexes(m_selectedFiles01); m_checkProxy->checkedState()->checkedBranchSourceModelIndexes(m_selectedDirectories01); if (m_selectedFiles01.isEmpty() && m_selectedDirectories01.isEmpty()) { QMessageBox::information(this, "Nothing Is Selected", "No files or directories are selected. Please select a file or directory."); return; } prepareChecksumDisplay01(); QGuiApplication::setOverrideCursor(Qt::WaitCursor); m_prepareForChecksum01 = QtConcurrent::map(this, &MainWindow::treeChecksum01); m_watcher02.setFuture(m_prepareForChecksum01); } if(ui->radioButton_useBrowse01->isChecked()) { if (m_browsedDirs01.isEmpty() && m_browsedFiles01.isEmpty()) { QMessageBox::information(this, "Nothing Is Selected", "No directories or files have been added. Please add a directory or file."); return; } prepareChecksumDisplay01(); QGuiApplication::setOverrideCursor(Qt::WaitCursor); m_prepareForChecksum01 = QtConcurrent::map(this, &MainWindow::browseChecksum01); m_watcher02.setFuture(m_prepareForChecksum01); } }
On Windows I was able to use QtConcurrent::run, but this gives me an error on MacOS. Currently, the error is:
/Users/crv/Documents/Programming/C++/Qt/Checksum1/Checksum1-V1.0-master/mainwindow.cpp:552: error: member reference type 'MainWindow *' is a pointer; did you mean to use '->'?
I have tried using this->MainWindow::treeChecksum01 and ->treeChecksum01, but both won't compile. Any help would be appreciated. I am using a 2023 MacBook Pro with the latest LTS version of Qt.
-
@jsulm Thanks for your reply. The following lines cause my error:
m_prepareForChecksum01 = QtConcurrent::map(this, &MainWindow::treeChecksum01); m_prepareForChecksum01 = QtConcurrent::map(this, &MainWindow::browseChecksum01);
Clang is what is giving me the errors. Any help you could provide would be much appreciated.
-
@jsulm Thanks for your reply. The following lines cause my error:
m_prepareForChecksum01 = QtConcurrent::map(this, &MainWindow::treeChecksum01); m_prepareForChecksum01 = QtConcurrent::map(this, &MainWindow::browseChecksum01);
Clang is what is giving me the errors. Any help you could provide would be much appreciated.
@TheCRV said in I Need Some Help With QtConcurrent On Mac:
Clang is what is giving me the errors
When you build your app? Or is it simply the code model in QtCreator complaining?
-
@TheCRV said in I Need Some Help With QtConcurrent On Mac:
Clang is what is giving me the errors
When you build your app? Or is it simply the code model in QtCreator complaining?
-
@TheCRV Of what type is m_prepareForChecksum01 and treeChecksum01/browseChecksum01?
-
@TheCRV Of what type is m_prepareForChecksum01 and treeChecksum01/browseChecksum01?
@Christian-Ehrlicher m_prepareForChecksum01 is a QFuture<Void>, and treeChecksum01 and browseChecksum01 are local member functions to MainWindow.
-
@Christian-Ehrlicher m_prepareForChecksum01 is a QFuture<Void>, and treeChecksum01 and browseChecksum01 are local member functions to MainWindow.
@TheCRV said in I Need Some Help With QtConcurrent On Mac:
d treeChecksum01 and browseChecksum01 are local member functions to MainWindow.
And what's the signature of those functions?
Please provide a minimal, compilable example so we can take a look on it - shouldn't be that hard here. -
@TheCRV said in I Need Some Help With QtConcurrent On Mac:
d treeChecksum01 and browseChecksum01 are local member functions to MainWindow.
And what's the signature of those functions?
Please provide a minimal, compilable example so we can take a look on it - shouldn't be that hard here.@Christian-Ehrlicher Thanks for your help. The signature of those functions are void and they take no parameters. I think that a minimally compilable example might be too much for here, so you can take a look at everything at: https://github.com/TheCRV/Checksum1-V1.0/tree/master
Again, I thank everyone for their help.
-
@Christian-Ehrlicher Thanks for your help. The signature of those functions are void and they take no parameters. I think that a minimally compilable example might be too much for here, so you can take a look at everything at: https://github.com/TheCRV/Checksum1-V1.0/tree/master
Again, I thank everyone for their help.
@TheCRV Sorry but your code does not match what you've shown here. I don't see why it should be so hard to create a minimal class with a function and a QFuture member so we can check it.
-
@TheCRV Sorry but your code does not match what you've shown here. I don't see why it should be so hard to create a minimal class with a function and a QFuture member so we can check it.
@Christian-Ehrlicher Okay, here is some code that gives me the same error:
My mainwindow.h file:
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QtConcurrent> #include <QFuture> #include <QDebug> QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } QT_END_NAMESPACE class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); private: Ui::MainWindow *ui; QVector<int> numbers; QFuture<void> future; void addNumbers1(); void addNumbers2(); }; #endif // MAINWINDOW_H
My mainwindow.cpp file:
#include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); addNumbers1(); } MainWindow::~MainWindow() { delete ui; } void MainWindow::addNumbers1() { future = QtConcurrent::map(this, &MainWindow::addNumbers2); } void MainWindow::addNumbers2() { for(int i = 0; i < 1000; ++i) { numbers.append(i); qDebug() << i; } }
My main.cpp file:
#include "mainwindow.h" #include <QApplication> #include <QLocale> #include <QTranslator> int main(int argc, char *argv[]) { QApplication a(argc, argv); QTranslator translator; const QStringList uiLanguages = QLocale::system().uiLanguages(); for (const QString &locale : uiLanguages) { const QString baseName = "Test_" + QLocale(locale).name(); if (translator.load(":/i18n/" + baseName)) { a.installTranslator(&translator); break; } } MainWindow w; w.show(); return a.exec(); }
Thanks again for any help. I'm pretty sure my problem has something to do with Qt 6, as with Qt 5.x I never had any trouble on Windows.
I would be perfectly happy if I could get QtConcurrent::run to work.
-
@TheCRV Sorry but your code does not match what you've shown here. I don't see why it should be so hard to create a minimal class with a function and a QFuture member so we can check it.
@Christian-Ehrlicher Okay, I have gotten QtConcurrent::run to work by changing my test code to this:
future = QtConcurrent::run(&MainWindow::addNumbers2, this);
I am still curious why map didn't work, but we can consider this solved. Thanks again.
-
@Christian-Ehrlicher Okay, I have gotten QtConcurrent::run to work by changing my test code to this:
future = QtConcurrent::run(&MainWindow::addNumbers2, this);
I am still curious why map didn't work, but we can consider this solved. Thanks again.
@TheCRV
From https://doc.qt.io/qt-6/qtconcurrent.html#map I was wondering which overload you were intending to match in yourQtConcurrent::map(this, &MainWindow::addNumbers2)
? That page is for Qt6, must be somemap()
overload was removed from Qt5 which matched yours?You said initially it was a Mac issue that worked on Windows. But now I think you are saying that was Qt5 and now is Qt6? Needs mentioning!
-
@TheCRV
From https://doc.qt.io/qt-6/qtconcurrent.html#map I was wondering which overload you were intending to match in yourQtConcurrent::map(this, &MainWindow::addNumbers2)
? That page is for Qt6, must be somemap()
overload was removed from Qt5 which matched yours?You said initially it was a Mac issue that worked on Windows. But now I think you are saying that was Qt5 and now is Qt6? Needs mentioning!
I really wonder whats so hard to provide a minimal example... for sure it's important for the problem to load a translator and init an ui... simply not understandable.
Your code does and can not compile with msvc and Qt6 ueither because there is no QtConcurrent::map() which takes those parameters.
class Foo : public QObject { public: Foo() { future = QtConcurrent::map(this, &Foo::addNumbers1); } private: QFuture<void> future; void addNumbers1() {} }; int main(int argc, char* argv[]) { QApplication a(argc, argv); Foo foo; return a.exec(); }
-
I really wonder whats so hard to provide a minimal example... for sure it's important for the problem to load a translator and init an ui... simply not understandable.
Your code does and can not compile with msvc and Qt6 ueither because there is no QtConcurrent::map() which takes those parameters.
class Foo : public QObject { public: Foo() { future = QtConcurrent::map(this, &Foo::addNumbers1); } private: QFuture<void> future; void addNumbers1() {} }; int main(int argc, char* argv[]) { QApplication a(argc, argv); Foo foo; return a.exec(); }
@Christian-Ehrlicher I do apologize for not providing a minimal-enough example. You have showed me how to do so. Thanks again.
-
-
@Christian-Ehrlicher I do apologize for not providing a minimal-enough example. You have showed me how to do so. Thanks again.
It's not about showing - it's about thinking on how to provide the needed information instead simply copying something together and hope that the others fiddle out what the real problem is. Esp. since this helps to find out the real problem by yourself.
So did you solve your problem now?
-
It's not about showing - it's about thinking on how to provide the needed information instead simply copying something together and hope that the others fiddle out what the real problem is. Esp. since this helps to find out the real problem by yourself.
So did you solve your problem now?
@Christian-Ehrlicher Yes, my problem is solved. I'm having another problem with including openSSL in my app. I will open another post for this.