Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. I Need Some Help With QtConcurrent On Mac

I Need Some Help With QtConcurrent On Mac

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 4 Posters 890 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TheCRV
    wrote on 2 Jan 2024, 06:08 last edited by
    #1

    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.

    J 1 Reply Last reply 2 Jan 2024, 06:15
    0
    • T TheCRV
      2 Jan 2024, 06:08

      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.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 2 Jan 2024, 06:15 last edited by
      #2

      @TheCRV Which line causes this error?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      T 1 Reply Last reply 2 Jan 2024, 12:51
      0
      • J jsulm
        2 Jan 2024, 06:15

        @TheCRV Which line causes this error?

        T Offline
        T Offline
        TheCRV
        wrote on 2 Jan 2024, 12:51 last edited by
        #3

        @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.

        J 1 Reply Last reply 2 Jan 2024, 12:57
        0
        • T TheCRV
          2 Jan 2024, 12:51

          @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.

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 2 Jan 2024, 12:57 last edited by
          #4

          @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?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          T 1 Reply Last reply 2 Jan 2024, 14:27
          1
          • J jsulm
            2 Jan 2024, 12:57

            @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?

            T Offline
            T Offline
            TheCRV
            wrote on 2 Jan 2024, 14:27 last edited by
            #5

            @jsulm Yes, it gives me the errors when I compile. The code model doesn't complain.

            C 1 Reply Last reply 2 Jan 2024, 15:47
            0
            • T TheCRV
              2 Jan 2024, 14:27

              @jsulm Yes, it gives me the errors when I compile. The code model doesn't complain.

              C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 2 Jan 2024, 15:47 last edited by
              #6

              @TheCRV Of what type is m_prepareForChecksum01 and treeChecksum01/browseChecksum01?

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              T 1 Reply Last reply 2 Jan 2024, 16:48
              1
              • C Christian Ehrlicher
                2 Jan 2024, 15:47

                @TheCRV Of what type is m_prepareForChecksum01 and treeChecksum01/browseChecksum01?

                T Offline
                T Offline
                TheCRV
                wrote on 2 Jan 2024, 16:48 last edited by
                #7

                @Christian-Ehrlicher m_prepareForChecksum01 is a QFuture<Void>, and treeChecksum01 and browseChecksum01 are local member functions to MainWindow.

                C 1 Reply Last reply 2 Jan 2024, 16:52
                0
                • T TheCRV
                  2 Jan 2024, 16:48

                  @Christian-Ehrlicher m_prepareForChecksum01 is a QFuture<Void>, and treeChecksum01 and browseChecksum01 are local member functions to MainWindow.

                  C Offline
                  C Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on 2 Jan 2024, 16:52 last edited by
                  #8

                  @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.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  T 1 Reply Last reply 2 Jan 2024, 17:51
                  0
                  • C Christian Ehrlicher
                    2 Jan 2024, 16:52

                    @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.

                    T Offline
                    T Offline
                    TheCRV
                    wrote on 2 Jan 2024, 17:51 last edited by
                    #9

                    @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.

                    C 1 Reply Last reply 2 Jan 2024, 18:11
                    0
                    • T TheCRV
                      2 Jan 2024, 17:51

                      @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.

                      C Offline
                      C Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on 2 Jan 2024, 18:11 last edited by
                      #10

                      @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.

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

                      T 2 Replies Last reply 2 Jan 2024, 19:59
                      0
                      • C Christian Ehrlicher
                        2 Jan 2024, 18:11

                        @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.

                        T Offline
                        T Offline
                        TheCRV
                        wrote on 2 Jan 2024, 19:59 last edited by TheCRV 1 Feb 2024, 20:12
                        #11

                        @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.

                        1 Reply Last reply
                        0
                        • C Christian Ehrlicher
                          2 Jan 2024, 18:11

                          @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.

                          T Offline
                          T Offline
                          TheCRV
                          wrote on 2 Jan 2024, 20:20 last edited by
                          #12

                          @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.

                          JonBJ 1 Reply Last reply 2 Jan 2024, 20:25
                          0
                          • T TheCRV
                            2 Jan 2024, 20:20

                            @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.

                            JonBJ Offline
                            JonBJ Offline
                            JonB
                            wrote on 2 Jan 2024, 20:25 last edited by JonB 1 Feb 2024, 20:26
                            #13

                            @TheCRV
                            From https://doc.qt.io/qt-6/qtconcurrent.html#map I was wondering which overload you were intending to match in your QtConcurrent::map(this, &MainWindow::addNumbers2)? That page is for Qt6, must be some map() 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!

                            C 1 Reply Last reply 2 Jan 2024, 21:19
                            0
                            • JonBJ JonB
                              2 Jan 2024, 20:25

                              @TheCRV
                              From https://doc.qt.io/qt-6/qtconcurrent.html#map I was wondering which overload you were intending to match in your QtConcurrent::map(this, &MainWindow::addNumbers2)? That page is for Qt6, must be some map() 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!

                              C Offline
                              C Offline
                              Christian Ehrlicher
                              Lifetime Qt Champion
                              wrote on 2 Jan 2024, 21:19 last edited by Christian Ehrlicher 1 Feb 2024, 21:24
                              #14

                              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();
                              }
                              

                              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                              Visit the Qt Academy at https://academy.qt.io/catalog

                              T 1 Reply Last reply 2 Jan 2024, 21:49
                              1
                              • C Christian Ehrlicher
                                2 Jan 2024, 21:19

                                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();
                                }
                                
                                T Offline
                                T Offline
                                TheCRV
                                wrote on 2 Jan 2024, 21:49 last edited by
                                #15

                                @Christian-Ehrlicher I do apologize for not providing a minimal-enough example. You have showed me how to do so. Thanks again.

                                C 1 Reply Last reply 2 Jan 2024, 22:17
                                0
                                • T TheCRV has marked this topic as solved on 2 Jan 2024, 21:49
                                • T TheCRV
                                  2 Jan 2024, 21:49

                                  @Christian-Ehrlicher I do apologize for not providing a minimal-enough example. You have showed me how to do so. Thanks again.

                                  C Offline
                                  C Offline
                                  Christian Ehrlicher
                                  Lifetime Qt Champion
                                  wrote on 2 Jan 2024, 22:17 last edited by
                                  #16

                                  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?

                                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                                  Visit the Qt Academy at https://academy.qt.io/catalog

                                  T 1 Reply Last reply 2 Jan 2024, 22:51
                                  0
                                  • C Christian Ehrlicher
                                    2 Jan 2024, 22:17

                                    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?

                                    T Offline
                                    T Offline
                                    TheCRV
                                    wrote on 2 Jan 2024, 22:51 last edited by
                                    #17

                                    @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.

                                    1 Reply Last reply
                                    0

                                    6/17

                                    2 Jan 2024, 15:47

                                    11 unread
                                    • Login

                                    • Login or register to search.
                                    6 out of 17
                                    • First post
                                      6/17
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • Users
                                    • Groups
                                    • Search
                                    • Get Qt Extensions
                                    • Unsolved