Import module appears LNK2021 error

I wrote the following code in VehicleBatteryFactGroup.cc

QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
qmlRegisterType<VehicleBatteryFactGroup>("QGroundControl.VehicleBatteryFactGroup",1,0,"VehicleBatteryFactGroup");

I would like to implement this module in BatteryIndicator.qml, however it threw out LNK2021 error unresolved external symbol “public: __cdecl VehicleBatteryFactGroup::VehicleBatteryFactGroup(class QObject *)” (??0VehicleBatteryFactGroup@@QEAA@PEAVQObject@@@Z) .

Should I add the path to the CMakeLists?Thanks in advance.

Hi,
Try build the project with “start debugging”. Just if you created a new file you add in the CMakeLists.

I didn’t create a new file. I increased new property batterycount whose type is int. I just want to import the property from VehicleBatteryFactGroup.cc to BatteryIndicator.qml. However, if I add qmlRegisterType in , LNK error appears.

code:

VehicleBatteryFactGroup::VehicleBatteryFactGroup(uint8_t batteryId, QObject* parent)
    : FactGroup             (1000, ":/json/Vehicle/BatteryFact.json", parent)
    , _batteryIdFact        (0, _batteryIdFactName,                 FactMetaData::valueTypeUint8)
    , _batteryFunctionFact  (0, _batteryFunctionFactName,           FactMetaData::valueTypeUint8)
    , _batteryTypeFact      (0, _batteryTypeFactName,               FactMetaData::valueTypeUint8)
    , _voltageFact          (0, _voltageFactName,                   FactMetaData::valueTypeDouble)
    , _currentFact          (0, _currentFactName,                   FactMetaData::valueTypeDouble)
    , _mahConsumedFact      (0, _mahConsumedFactName,               FactMetaData::valueTypeDouble)
    , _temperatureFact      (0, _temperatureFactName,               FactMetaData::valueTypeDouble)
    , _percentRemainingFact (0, _percentRemainingFactName,          FactMetaData::valueTypeDouble)
    , _timeRemainingFact    (0, _timeRemainingFactName,             FactMetaData::valueTypeDouble)
    , _timeRemainingStrFact (0, _timeRemainingStrFactName,          FactMetaData::valueTypeString)
    , _chargeStateFact      (0, _chargeStateFactName,               FactMetaData::valueTypeUint8)
    , _instantPowerFact     (0, _instantPowerFactName,              FactMetaData::valueTypeDouble)

{
    _addFact(&_batteryIdFact,               _batteryIdFactName);
    _addFact(&_batteryFunctionFact,         _batteryFunctionFactName);
    _addFact(&_batteryTypeFact,             _batteryTypeFactName);
    _addFact(&_voltageFact,                 _voltageFactName);
    _addFact(&_currentFact,                 _currentFactName);
    _addFact(&_mahConsumedFact,             _mahConsumedFactName);
    _addFact(&_temperatureFact,             _temperatureFactName);
    _addFact(&_percentRemainingFact,        _percentRemainingFactName);
    _addFact(&_timeRemainingFact,           _timeRemainingFactName);
    _addFact(&_timeRemainingStrFact,        _timeRemainingStrFactName);
    _addFact(&_chargeStateFact,             _chargeStateFactName);
    _addFact(&_instantPowerFact,            _instantPowerFactName);


    _batteryIdFact.setRawValue          (batteryId);
    _batteryFunctionFact.setRawValue    (MAV_BATTERY_FUNCTION_UNKNOWN);
    _batteryTypeFact.setRawValue        (MAV_BATTERY_TYPE_UNKNOWN);
    _voltageFact.setRawValue            (qQNaN());
    _currentFact.setRawValue            (qQNaN());
    _mahConsumedFact.setRawValue        (qQNaN());
    _temperatureFact.setRawValue        (qQNaN());
    _percentRemainingFact.setRawValue   (qQNaN());
    _timeRemainingFact.setRawValue      (qQNaN());
    _chargeStateFact.setRawValue        (MAV_BATTERY_CHARGE_STATE_UNDEFINED);
    _instantPowerFact.setRawValue       (qQNaN());

    connect(&_timeRemainingFact, &Fact::rawValueChanged, this, &VehicleBatteryFactGroup::_timeRemainingChanged);

    QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
    qmlRegisterType<VehicleBatteryFactGroup>("QGroundControl.VehicleBatteryFactGroup",1,0,"VehicleBatteryFactGroup");
}