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. File is not defined.
Forum Updated to NodeBB v4.3 + New Features

File is not defined.

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
24 Posts 6 Posters 5.1k 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.
  • J Offline
    J Offline
    JennyAug13
    wrote on last edited by
    #9

    Following is the .pro file being used

    QT += quick
    CONFIG += c++11
    
    DEFINES += QT_DEPRECATED_WARNINGS
    
    
    SOURCES += \
            main.cpp \
           Info.cpp
    
    RESOURCES += qml.qrc
    
    # Additional import path used to resolve QML modules in Qt Creator's code model
    QML_IMPORT_PATH =
    
    # Additional import path used to resolve QML modules just for Qt Quick Designer
    QML_DESIGNER_IMPORT_PATH =
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    
    
    J.HilkJ 1 Reply Last reply
    0
    • J JennyAug13

      Following is the .pro file being used

      QT += quick
      CONFIG += c++11
      
      DEFINES += QT_DEPRECATED_WARNINGS
      
      
      SOURCES += \
              main.cpp \
             Info.cpp
      
      RESOURCES += qml.qrc
      
      # Additional import path used to resolve QML modules in Qt Creator's code model
      QML_IMPORT_PATH =
      
      # Additional import path used to resolve QML modules just for Qt Quick Designer
      QML_DESIGNER_IMPORT_PATH =
      
      # Default rules for deployment.
      qnx: target.path = /tmp/$${TARGET}/bin
      else: unix:!android: target.path = /opt/$${TARGET}/bin
      !isEmpty(target.path): INSTALLS += target
      
      
      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #10

      @JennyAug13 and main.cpp and info.h and info.cpp are all in the same folder, on your drive?


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JennyAug13
        wrote on last edited by
        #11

        Yes, all are in same folder

        JonBJ 1 Reply Last reply
        0
        • J JennyAug13

          Yes, all are in same folder

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #12

          @JennyAug13
          I think then that you need to show the actual content of your Info.h. According to what you have said the compiler is actually finding the file --- else you would have had a "no such include file" error --- so a message of ReferenceError: Info is not defined would imply that at whatever line that occurs (assuming that source file has already met the necessary included Info.h by that point) the .h has not actually defined the Info class correctly.... You might also like to show us the actual source line which generated that error, together with "proof" that Info.h has been included prior to the line....

          P.S.
          Do ensure you have done a "clean" rebuild. This kind of error does crop up when, say, you have added an include file to a source file but not properly rebuilt, and the compiler uses cached files for the previous state where the header had not been included....

          1 Reply Last reply
          2
          • dheerendraD Offline
            dheerendraD Offline
            dheerendra
            Qt Champions 2022
            wrote on last edited by
            #13

            Looks like somewhere you are doing the cycle.

            1. Info.h is included in one.h.
            2. one.h is included in two.h and
            3. two.h includes info.h again.

            Dheerendra
            @Community Service
            Certified Qt Specialist
            http://www.pthinks.com

            JonBJ J 2 Replies Last reply
            2
            • dheerendraD dheerendra

              Looks like somewhere you are doing the cycle.

              1. Info.h is included in one.h.
              2. one.h is included in two.h and
              3. two.h includes info.h again.
              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #14

              @dheerendra
              Would your situation actually result in ReferenceError: Info is not defined? I would have thought it would be more like "duplicate definition found"?

              If this does turn out to be the case, the OP needs to put in #ifndef guards to prevent re-inclusion.

              1 Reply Last reply
              1
              • dheerendraD dheerendra

                Looks like somewhere you are doing the cycle.

                1. Info.h is included in one.h.
                2. one.h is included in two.h and
                3. two.h includes info.h again.
                J Offline
                J Offline
                JennyAug13
                wrote on last edited by
                #15

                @dheerendra Nope, it is included only once... inside my info.cpp file and i have only one header file and one source file as of now (Info.cpp and Info.h)

                1 Reply Last reply
                0
                • GrecKoG Offline
                  GrecKoG Offline
                  GrecKo
                  Qt Champions 2018
                  wrote on last edited by
                  #16

                  That's a JS/QML error, where does it occur and can you share some code ?

                  ODБOïO 1 Reply Last reply
                  3
                  • J Offline
                    J Offline
                    JennyAug13
                    wrote on last edited by JennyAug13
                    #17

                    This is the actual error:

                    qrc:/Theme/Icons.qml:33: ReferenceError: Info is not defined
                    qrc:/Theme/Font.qml:53: ReferenceError: Info is not defined
                    

                    and in the lines of these files, following lines of code is there

                    @qrc:/Theme/Icons.qml:33:   
                    
                    readonly property string imagePath: Info.getQMLResourcePath() + "Theme/Images/"
                    
                    @qrc:/Theme/Font.qml:53:
                    
                    source: Info.getQMLResourcePath() + "Theme/Fonts/ProLight.otf";
                    
                    
                    1 Reply Last reply
                    0
                    • GrecKoG Offline
                      GrecKoG Offline
                      GrecKo
                      Qt Champions 2018
                      wrote on last edited by
                      #18

                      Did you use qmlRegisterSingletonType on your Info type ?
                      And then added an import line for the module in your qml file ?

                      1 Reply Last reply
                      3
                      • GrecKoG GrecKo

                        That's a JS/QML error, where does it occur and can you share some code ?

                        ODБOïO Offline
                        ODБOïO Offline
                        ODБOï
                        wrote on last edited by
                        #19

                        @GrecKo said in File is not defined.:

                        That's a JS/QML error

                        good catch

                        1 Reply Last reply
                        0
                        • J Offline
                          J Offline
                          JennyAug13
                          wrote on last edited by
                          #20

                          Here is the code inside my "Info.cpp" file for your reference.

                          // own header
                          #include "Info.h"
                          #include <QCoreApplication>
                          #include <QQmlEngine>
                          #include <QDir>
                          
                          Q_LOGGING_CATEGORY(LC_Info, "Info")
                          
                          // Root direcoty
                          const QString Info::ASSETS_FOLDER_NAME                = "assets";
                          
                          //// System & User directories
                          const QString Info::SYSTEM_ASSETS_FOLDER_NAME         = "system";
                          const QString Info::USER_ASSETS_FOLDER_NAME           = "user";
                          const QString Info::SETTINGS_ASSETS_FOLDER_NAME       = "settings";
                          const QString Info::RESOURCE_ASSETS_FOLDER_NAME       = "resources";
                          
                          //// System directories
                          const QString Info::THERAPY_ASSETS_FOLDER_NAME        = "therapies";
                          const QString Info::LANGUAGE_ASSETS_FOLDER_NAME       = "lang";
                          
                          //// User directories
                          const QString Info::STATISTICS_FOLDER_NAME            = "statistics";
                          const QString Info::EMG_DATA_FOLDER_NAME              = "emg-data";
                          const QString Info::FAVORITES_FOLDER_NAME             = "favorites";
                          const QString Info::PATIENT_PROGRAMS_FOLDER_NAME      = "patient-programs";
                          const QString Info::LOG_FOLDER_NAME                   = "log";
                          
                          //// Static filenames
                          const QString Info::DEFAULT_THERAPY_VALUES_FILE_NAME  = "therapies.json";
                          
                          Info::Info()
                            : QObject(),
                              m_buildInQmlResource(true)
                          {
                            QString     envAssetsPath = qgetenv("ASSETS_PATH");
                            QStringList assetsSearchPaths;
                          
                            if (!envAssetsPath.isEmpty()) {
                              assetsSearchPaths.append(envAssetsPath);
                            }
                          
                            if (QCoreApplication::instance() != nullptr) {
                              assetsSearchPaths.append(QCoreApplication::applicationDirPath());
                            }
                            assetsSearchPaths.append(QDir::currentPath());
                          
                            foreach (QString path, assetsSearchPaths) {
                          
                              QDir d(path + QDir::separator() + ASSETS_FOLDER_NAME);
                          
                              // Found Assets folder:
                              if (d.exists()) {
                                m_assetsPath = d.absolutePath() + QDir::separator();
                                break;
                              }
                            }
                          
                            // User assets directory name can be adjusted through environment
                            // variable. This is mainly for defining a spearate path for testing
                            // purposes (e.g. unit tests)
                            QByteArray envUserAssetsName = qgetenv("USER_ASSETS_NAME");
                            m_userAssetsFolderName = envUserAssetsName.isEmpty() ?
                                  USER_ASSETS_FOLDER_NAME :
                                  envUserAssetsName;
                          }
                          
                          bool Info::createPath(const QString & path)
                          {
                            QDir d(path);
                            if (d.exists()) {
                              return true;
                            }
                            return d.mkpath(path);
                          }
                          
                          Info *Info::getInstance()
                          {
                            static Info info;
                            return &info;
                          }
                          
                          QObject *Info::getInstanceQml(QQmlEngine *engine, QJSEngine *scriptEngine)
                          {
                            Q_UNUSED(engine)
                            Q_UNUSED(scriptEngine)
                          
                            QObject * inst = Info::getInstance();
                          
                            QQmlEngine::setObjectOwnership(inst, QQmlEngine::CppOwnership);
                          
                            return inst;
                          }
                          
                          QString Info::getUserPath()
                          {
                            return getInstance()->m_assetsPath +
                                getInstance()->m_userAssetsFolderName +
                                QDir::separator();
                          }
                          
                          QString Info::getUserSettingsPath()
                          {
                            return getInstance()->getUserPath() +
                                Info::SETTINGS_ASSETS_FOLDER_NAME +
                                QDir::separator();
                          }
                          
                          QString Info::getStatisticsPath()
                          {
                            return getInstance()->getUserPath() +
                                Info::STATISTICS_FOLDER_NAME +
                                QDir::separator();
                          }
                          
                          QString Info::getEmgDataPath()
                          {
                            return getInstance()->getUserPath() +
                                Info::EMG_DATA_FOLDER_NAME +
                                QDir::separator();
                          }
                          
                          QString Info::getFavoritesPath()
                          {
                            return getInstance()->getUserPath() +
                                Info::FAVORITES_FOLDER_NAME +
                                QDir::separator();
                          }
                          
                          QString Info::getLogPath()
                          {
                            return getInstance()->getUserPath() +
                                Info::LOG_FOLDER_NAME +
                                QDir::separator();
                          }
                          
                          QString Info::getPatientProgramsPath()
                          {
                            return getInstance()->getUserPath() +
                                Info::PATIENT_PROGRAMS_FOLDER_NAME +
                                QDir::separator();
                          }
                          
                          QString Info::getSystemPath()
                          {
                            return getInstance()->m_assetsPath +
                                Info::SYSTEM_ASSETS_FOLDER_NAME +
                                QDir::separator();
                          }
                          
                          QString Info::getAssetsPath()
                          {
                            return getInstance()->m_assetsPath +
                                QDir::separator();
                          }
                          
                          QString Info::getLangPath()
                          {
                            return getInstance()->getSystemPath() +
                                Info::LANGUAGE_ASSETS_FOLDER_NAME +
                                QDir::separator();
                          }
                          
                          QString Info::getResourcePath()
                          {
                            return getInstance()->getSystemPath() +
                                Info::RESOURCE_ASSETS_FOLDER_NAME +
                                QDir::separator();
                          }
                          
                          QString Info::getQMLResourcePath()
                          {
                            return getInstance()->m_buildInQmlResource ? "qrc:/" : ("file:/" + Info::getResourcePath());
                          }
                          
                          QString Info::getSystemTherapyPath()
                          {
                            return getInstance()->getSystemPath() +
                                Info::THERAPY_ASSETS_FOLDER_NAME +
                                QDir::separator();
                          }
                          
                          QString Info::getSystemSettingsPath()
                          {
                            return getInstance()->getSystemPath() +
                                Info::SETTINGS_ASSETS_FOLDER_NAME +
                                QDir::separator();
                          }
                          
                          bool Info::init()
                          {
                            bool ok = true;
                          
                            qCDebug(LC_Info) << "************************************";
                            qCDebug(LC_Info) << "Initialising Neurotab Assets File System:";
                          
                            qCDebug(LC_Info) << "Assets directory: " << getInstance()->m_assetsPath;
                          
                            // Assets path MUST exist!!!
                            QDir ntSysPath(getSystemPath());
                            if (!ntSysPath.exists()) {
                              qCCritical(LC_Info) << "Assets / System directory MUST exist! ("
                                                          << getSystemPath()
                                                          << ")";
                              return false;
                            }
                          
                            if (!createPath(getUserPath())) {
                              qCCritical(LC_Info) << "could not create " << getUserPath();
                              ok = false;
                            }
                            if (!createPath(getLogPath())) {
                              qCCritical(LC_Info) << "could not create " << getLogPath();
                              ok = false;
                            }
                            if (!createPath(getUserSettingsPath())) {
                              qCCritical(LC_Info) << "could not create " << getUserSettingsPath();
                              ok = false;
                            }
                            if (!createPath(getStatisticsPath())) {
                              qCCritical(LC_Info) << "could not create " << getStatisticsPath();
                              ok = false;
                            }
                            if (!createPath(getEmgDataPath())) {
                              qCCritical(LC_Info) << "could not create " << getEmgDataPath();
                              ok = false;
                            }
                            if (!createPath(getPatientProgramsPath())) {
                              qCCritical(LC_Info) << "could not create " << getPatientProgramsPath();
                              ok = false;
                            }
                            if (!createPath(getFavoritesPath())) {
                              qCCritical(LC_Info) << "could not create " << getFavoritesPath();
                              ok = false;
                            }
                          
                            qCDebug(LC_Info) << "done\n";
                          
                            return ok;
                          }
                          
                          void Info::resetAllUserAssets()
                          {
                            QDir d(getUserPath());
                            d.removeRecursively();
                            init();
                          }
                          
                          void Info::useBuildInQml(bool buildIn)
                          {
                            getInstance()->m_buildInQmlResource = buildIn;
                          }
                          
                          1 Reply Last reply
                          0
                          • dheerendraD Offline
                            dheerendraD Offline
                            dheerendra
                            Qt Champions 2022
                            wrote on last edited by
                            #21

                            This class looks great. This is the c++ claas. If u want to see this class at qml side, it needs to be registered to qml using qmlregistertype etc methods. Looks like your class is not exposed to qml. Please check and if not please do so. Search in Google or qt assistant for how to expose c++ class to qml.

                            Dheerendra
                            @Community Service
                            Certified Qt Specialist
                            http://www.pthinks.com

                            1 Reply Last reply
                            1
                            • J Offline
                              J Offline
                              JennyAug13
                              wrote on last edited by
                              #22

                              I have registered to qml using qmlregistertype method and included it inside my qml file as follows. But it gives following errors when i build.

                              inside my main.cpp file

                              qmlRegisterType <Info>("NT.Cpp",1,0, "Info");
                              

                              inside my Icons.qml file it is included as

                              import NT.Cpp 1.0
                              

                              But many errors appear as follows:

                              /opt/Qt/5.6.3/gcc_64/include/QtQml/qqmlprivate.h:93: error: within this context
                                   class QQmlElement : public T
                                         ^
                              
                              /Info.h:98: error: ‘Info::Info()’ is private
                                   Info();
                                   ^
                              /opt/Qt/5.6.3/gcc_64/include/QtQml/qqmlprivate.h:93: ‘QQmlPrivate::QQmlElement<Info>::QQmlElement()’ is implicitly deleted because the default definition would be ill-formed:
                                   class QQmlElement : public T
                                         ^
                              
                              
                              1 Reply Last reply
                              0
                              • dheerendraD Offline
                                dheerendraD Offline
                                dheerendra
                                Qt Champions 2022
                                wrote on last edited by
                                #23

                                Looks like you have private constructor in Info class. Can you show the info.h file ? Above post only has implementation file.

                                Dheerendra
                                @Community Service
                                Certified Qt Specialist
                                http://www.pthinks.com

                                1 Reply Last reply
                                0
                                • GrecKoG Offline
                                  GrecKoG Offline
                                  GrecKo
                                  Qt Champions 2018
                                  wrote on last edited by
                                  #24

                                  Yes it looks like a private constructor, and with a getInstance method to get the singleton instance.

                                  Use qmlRegisterSingletonType and not qmlRegisterType. If you use this instance in c++ too, don't forget to set the object ownership (with setObjectOwnership) to QQmlEngine::CppOwnership.

                                  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