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.
QtWS25 Last Chance

File is not defined.

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
24 Posts 6 Posters 4.2k 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 14 Dec 2018, 09:02 last edited by
    #1

    In my project, i have already included a Info.cpp file under my Sources folder but it still gives the error,

    ReferenceError: Info is not defined
    

    And i can see the file included inside my .pro file already.

    How can I get out of this error?

    O 1 Reply Last reply 14 Dec 2018, 09:08
    0
    • J JennyAug13
      14 Dec 2018, 09:02

      In my project, i have already included a Info.cpp file under my Sources folder but it still gives the error,

      ReferenceError: Info is not defined
      

      And i can see the file included inside my .pro file already.

      How can I get out of this error?

      O Offline
      O Offline
      ODБOï
      wrote on 14 Dec 2018, 09:08 last edited by
      #2

      @JennyAug13 hi,
      when i have this kind of errors i usually do this combo :

      • close the project
      • delete your projects build folder
      • delete your .pro.user file
      • open the .pro with qtCreator
      • re-configure / qmake
      1 Reply Last reply
      1
      • J Offline
        J Offline
        JennyAug13
        wrote on 14 Dec 2018, 09:13 last edited by
        #3

        I did as follows, but getting the same error.

        O 1 Reply Last reply 14 Dec 2018, 09:26
        0
        • J JennyAug13
          14 Dec 2018, 09:13

          I did as follows, but getting the same error.

          O Offline
          O Offline
          ODБOï
          wrote on 14 Dec 2018, 09:26 last edited by
          #4

          @JennyAug13 Do you have Info.h also?
          are you including Info in the file where you use it ?

          #include "Info.h"
          
          1 Reply Last reply
          0
          • J Offline
            J Offline
            JennyAug13
            wrote on 14 Dec 2018, 09:35 last edited by
            #5

            Yes I have included it already

            1 Reply Last reply
            0
            • J Offline
              J Offline
              JennyAug13
              wrote on 14 Dec 2018, 09:38 last edited by
              #6

              Also i made a .pri file and also added the sources into it

              J 1 Reply Last reply 14 Dec 2018, 09:45
              0
              • J JennyAug13
                14 Dec 2018, 09:38

                Also i made a .pri file and also added the sources into it

                J Offline
                J Offline
                J.Hilk
                Moderators
                wrote on 14 Dec 2018, 09:45 last edited by
                #7

                @JennyAug13
                can you show us your *.pro file and where you try to include the info.h ?


                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 14 Dec 2018, 09:48 last edited by
                  #8

                  0_1544780884821_Forums2.JPG

                  At the end of my .pro file

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    JennyAug13
                    wrote on 14 Dec 2018, 10:14 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 1 Reply Last reply 14 Dec 2018, 10:18
                    0
                    • J JennyAug13
                      14 Dec 2018, 10:14

                      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 Offline
                      J Offline
                      J.Hilk
                      Moderators
                      wrote on 14 Dec 2018, 10:18 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 14 Dec 2018, 10:19 last edited by
                        #11

                        Yes, all are in same folder

                        J 1 Reply Last reply 14 Dec 2018, 10:27
                        0
                        • J JennyAug13
                          14 Dec 2018, 10:19

                          Yes, all are in same folder

                          J Offline
                          J Offline
                          JonB
                          wrote on 14 Dec 2018, 10:27 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
                          • D Offline
                            D Offline
                            dheerendra
                            Qt Champions 2022
                            wrote on 14 Dec 2018, 10:30 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

                            J J 2 Replies Last reply 14 Dec 2018, 10:33
                            2
                            • D dheerendra
                              14 Dec 2018, 10:30

                              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
                              JonB
                              wrote on 14 Dec 2018, 10:33 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
                              • D dheerendra
                                14 Dec 2018, 10:30

                                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 14 Dec 2018, 10:38 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 14 Dec 2018, 10:40 last edited by
                                  #16

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

                                  O 1 Reply Last reply 14 Dec 2018, 19:32
                                  3
                                  • J Offline
                                    J Offline
                                    JennyAug13
                                    wrote on 14 Dec 2018, 10:44 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 14 Dec 2018, 11:07 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
                                        14 Dec 2018, 10:40

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

                                        O Offline
                                        O Offline
                                        ODБOï
                                        wrote on 14 Dec 2018, 19:32 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 16 Dec 2018, 13:10 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

                                          5/24

                                          14 Dec 2018, 09:35

                                          topic:navigator.unread, 19
                                          • Login

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