Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Possible Typo in Popular "Learn Qt 5" Book by Nicholas Sherrif?
Forum Updated to NodeBB v4.3 + New Features

Possible Typo in Popular "Learn Qt 5" Book by Nicholas Sherrif?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 238 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.
  • B Offline
    B Offline
    bluesanta
    wrote on last edited by
    #1

    Hello,

    I'm new to Qt and my c++ skills are intermediate student-level.

    I'm working through Nicholas Sherrif's book, Learn Qt 5, and I have come to a spot where even the example code does not seem to compile properly.

    My full repository can be found at this link here.

    At this point, I have copy/pasted everything from the example code, Chapter 4, as can be found at this link here.

    The bug is with a complicated bit of code that is above my skill level.

    It shows up in the file cm/cm-lib/source/controllers/command-controller.cpp.

    The compiler error is as follows:

    ..<directory-listings>/command-controller.cpp:39: error: no matching function for call to ‘QQmlListProperty<cm::framework::Command>::QQmlListProperty(cm::controllers::CommandController*, QList<cm::framework::Command*>&)’
    
    ../../cm-lib/source/controllers/command-controller.cpp: In member function ‘QQmlListProperty<cm::framework::Command> cm::controllers::CommandController::ui_createClientViewContextCommands()’:
    
    ../../cm-lib/source/controllers/command-controller.cpp:39:91: error: no matching function for call to ‘QQmlListProperty<cm::framework::Command>::QQmlListProperty(cm::controllers::CommandController*, QList<cm::framework::Command*>&)’
    
       39 |     return QQmlListProperty<Command>(this, implementation->createClientViewContextCommands);
          |                                                                                           ^
    

    Here is the full file content for command-controller.cpp:

    #include "command-controller.h"
    
    #include <QList>
    #include <QDebug>
    
    using namespace cm::framework;
    
    namespace cm {
    namespace controllers {
    
    class CommandController::Implementation
    {
    public:
        Implementation(CommandController* _commandController)
            : commandController(_commandController)
        {
            Command* createClientSaveCommand = new Command( commandController, QChar( 0xf0c7 ), "Save" );
            QObject::connect( createClientSaveCommand, &Command::executed, commandController, &CommandController::onCreateClientSaveExecuted );
            createClientViewContextCommands.append( createClientSaveCommand );
        }
    
        CommandController* commandController{nullptr};
    
        QList<Command*> createClientViewContextCommands{};
    };
    
    CommandController::CommandController(QObject* parent)
        : QObject(parent)
    {
        implementation.reset(new Implementation(this));
    }
    
    CommandController::~CommandController()
    {
    }
    
    QQmlListProperty<Command> CommandController::ui_createClientViewContextCommands()
    {
        return QQmlListProperty<Command>(this, implementation->createClientViewContextCommands);
    }
    
    void CommandController::onCreateClientSaveExecuted()
    {
        qDebug() << "You executed the Save command!";
    }
    
    }}
    

    Based on what I am reading in the error output, it would seem that the function in use in for QQmlListProperty... is not properly declared, or even mentioned, in the header file.

    The header file is beyond my skill level.

    Here is a copy of the header command-controller.h:

    #ifndef COMMANDCONTROLLER_H
    #define COMMANDCONTROLLER_H
    
    #include <QObject>
    #include <QtQml/QQmlListProperty>
    #include <cm-lib_global.h>
    #include <framework/command.h>
    
    namespace cm {
    namespace controllers {
    
    class CMLIBSHARED_EXPORT CommandController : public QObject
    {
        Q_OBJECT
        Q_PROPERTY(QQmlListProperty<cm::framework::Command> ui_createClientViewContextCommands READ ui_createClientViewContextCommands CONSTANT)
    
    public:
        explicit CommandController(QObject* _parent = nullptr);
        ~CommandController();
    
        QQmlListProperty<framework::Command> ui_createClientViewContextCommands();
    
    public slots:
        void onCreateClientSaveExecuted();
    
    private:
        class Implementation;
        QScopedPointer<Implementation> implementation;
    };
    
    }}
    
    #endif
    

    I have found another post here on the Qt forums that seems to be dealing with the exact same line of code from the exact same book.

    However, this person seems to understand the code more thoroughly, and I also get the impression that their specific issue was just a little bit different.

    Can anyone help with this, please?

    Thank you.

    M 1 Reply Last reply
    0
    • B bluesanta

      Hello,

      I'm new to Qt and my c++ skills are intermediate student-level.

      I'm working through Nicholas Sherrif's book, Learn Qt 5, and I have come to a spot where even the example code does not seem to compile properly.

      My full repository can be found at this link here.

      At this point, I have copy/pasted everything from the example code, Chapter 4, as can be found at this link here.

      The bug is with a complicated bit of code that is above my skill level.

      It shows up in the file cm/cm-lib/source/controllers/command-controller.cpp.

      The compiler error is as follows:

      ..<directory-listings>/command-controller.cpp:39: error: no matching function for call to ‘QQmlListProperty<cm::framework::Command>::QQmlListProperty(cm::controllers::CommandController*, QList<cm::framework::Command*>&)’
      
      ../../cm-lib/source/controllers/command-controller.cpp: In member function ‘QQmlListProperty<cm::framework::Command> cm::controllers::CommandController::ui_createClientViewContextCommands()’:
      
      ../../cm-lib/source/controllers/command-controller.cpp:39:91: error: no matching function for call to ‘QQmlListProperty<cm::framework::Command>::QQmlListProperty(cm::controllers::CommandController*, QList<cm::framework::Command*>&)’
      
         39 |     return QQmlListProperty<Command>(this, implementation->createClientViewContextCommands);
            |                                                                                           ^
      

      Here is the full file content for command-controller.cpp:

      #include "command-controller.h"
      
      #include <QList>
      #include <QDebug>
      
      using namespace cm::framework;
      
      namespace cm {
      namespace controllers {
      
      class CommandController::Implementation
      {
      public:
          Implementation(CommandController* _commandController)
              : commandController(_commandController)
          {
              Command* createClientSaveCommand = new Command( commandController, QChar( 0xf0c7 ), "Save" );
              QObject::connect( createClientSaveCommand, &Command::executed, commandController, &CommandController::onCreateClientSaveExecuted );
              createClientViewContextCommands.append( createClientSaveCommand );
          }
      
          CommandController* commandController{nullptr};
      
          QList<Command*> createClientViewContextCommands{};
      };
      
      CommandController::CommandController(QObject* parent)
          : QObject(parent)
      {
          implementation.reset(new Implementation(this));
      }
      
      CommandController::~CommandController()
      {
      }
      
      QQmlListProperty<Command> CommandController::ui_createClientViewContextCommands()
      {
          return QQmlListProperty<Command>(this, implementation->createClientViewContextCommands);
      }
      
      void CommandController::onCreateClientSaveExecuted()
      {
          qDebug() << "You executed the Save command!";
      }
      
      }}
      

      Based on what I am reading in the error output, it would seem that the function in use in for QQmlListProperty... is not properly declared, or even mentioned, in the header file.

      The header file is beyond my skill level.

      Here is a copy of the header command-controller.h:

      #ifndef COMMANDCONTROLLER_H
      #define COMMANDCONTROLLER_H
      
      #include <QObject>
      #include <QtQml/QQmlListProperty>
      #include <cm-lib_global.h>
      #include <framework/command.h>
      
      namespace cm {
      namespace controllers {
      
      class CMLIBSHARED_EXPORT CommandController : public QObject
      {
          Q_OBJECT
          Q_PROPERTY(QQmlListProperty<cm::framework::Command> ui_createClientViewContextCommands READ ui_createClientViewContextCommands CONSTANT)
      
      public:
          explicit CommandController(QObject* _parent = nullptr);
          ~CommandController();
      
          QQmlListProperty<framework::Command> ui_createClientViewContextCommands();
      
      public slots:
          void onCreateClientSaveExecuted();
      
      private:
          class Implementation;
          QScopedPointer<Implementation> implementation;
      };
      
      }}
      
      #endif
      

      I have found another post here on the Qt forums that seems to be dealing with the exact same line of code from the exact same book.

      However, this person seems to understand the code more thoroughly, and I also get the impression that their specific issue was just a little bit different.

      Can anyone help with this, please?

      Thank you.

      M Offline
      M Offline
      MrTscha
      wrote on last edited by
      #2

      @bluesanta I guess you are using Qt 6?
      There are some changes between Qt 5 and Qt 6. For example the constructor of QQmlListProperty does not take a reference any more:

      https://doc.qt.io/qt-6/qml-changes-qt6.html#removed-api

      Changing the code to

      QQmlListProperty<Command> CommandController::ui_createClientViewContextCommands()
      {
          return QQmlListProperty<Command>(this, &implementation->createClientViewContextCommands);
      }
      

      should work.

      1 Reply Last reply
      0

      • Login

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