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.
Qt 6.11 is out! See what's new in the release blog

File is not defined.

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
24 Posts 6 Posters 8.8k 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.
  • 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
                Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
                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
                https://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
                    Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
                    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
                    https://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