Question

I'm a student programmer and I am using Qt to build some GUI applications for work and I have been running into moc issues over and over again. I was hoping for a solution to the current problem that I am having; however, if anyone more veteraned in Qt could shed some light on how to properly handle these files while making changes to your cpp file(s) I'd appreciate any help. In my most recent change (sorry I can't post what it did look like, because it's obviously been restructured) I was validating data by nesting a function inside of my checkData function. Because I would like a specific error to appear for each field that might be invalid I began to create a function for each QLineEdit. I realized that this would not work (or at least make more work) then instead of just providing sequenced checks of information. Below is the new code without the original nested function:

void InjectionDialog::checkData() {
   bool validateFluidVelocity;
   QString tempStrFluidVelocity;
   tempStrFluidVelocity = ui->lineEditFluidVelocity->text();
   double convertedFluidVelocity =
      tempStrFluidVelocity.toDouble(&validateFluidVelocity);
   if (validateFluidVelocity == false) {
      QErrorMessage validateErrorFluidVelocityError;
      validateErrorFluidVelocityError.
         showMessage("Fluid velocity input is invalid");
      validateErrorFluidVelocityError.exec();
   }
   else {
      transData.lineEditFluidVelocity = convertedFluidVelocity;
   }
   bool validateFluidMassFlow;
   QString tempStrFluidMassFlow;
   tempStrFluidMassFlow = ui->lineEditFluidMassFlow->text();
   double convertedFluidMassFlow =
      tempStrFluidMassFlow.toDouble(&validateFluidMassFlow);
   if (validateFluidMassFlow == false) {
      QErrorMessage validateErrorFluidMassFlowError;
      validateErrorFluidMassFlowError.
         showMessage("Fluid mass flow input is invalid");
      validateErrorFluidMassFlowError.exec();
   }
   else {
      transData.lineEditFluidMassFlow = convertedFluidMassFlow;
   }
   bool validateParticleVelocity;
   QString tempStrParticleVelocity;
   tempStrParticleVelocity = ui->lineEditParticleVelocity->text();
   double convertedParticleVelocity =
      tempStrParticleVelocity.toDouble(&validateParticleVelocity);
   if (validateParticleVelocity == false) {
      QErrorMessage validateErrorParticleVelocity;
      validateErrorParticleVelocity.
         showMessage("Particle velocity input is invalid");
      validateErrorParticleVelocity.exec();
   }
   else {
      transData.lineEditParitcle_sic_Velocity = convertedParticleVelocity;
   }
   bool validateParticleMassFlow;
   QString tempStrParticleMassFlow;
   tempStrParticleMassFlow = ui->lineEditParticleMassFlow->text();
   double convertedParticleMassFlow =
      tempStrParticleMassFlow.toDouble(&validateParticleMassFlow);
   if (validateParticleMassFlow == false) {
      QErrorMessage validateErrorParticleMassFlow;
      validateErrorParticleMassFlow.
         showMessage("Particle mass flow input is invalid");
      validateErrorParticleMassFlow.exec();
   }
   else {
      transData.lineEditParticleMassFlow = convertedParticleMassFlow;
   }
}

Initially I had InjectionDialog::checkFluidVelociy for the first check but decided against it pretty quickly. Now with the code restructured I receive the error:

In function 'InjectionDialog::checkFluidVelocity(QMetaObject::Call, int, void**)': this error is referenced to moc_injectionDialog.o

unidentified reference to 'InjectionDialog::checkFluidVelocity()' this error is referenced to moc_injectiondialog.cpp

In moc_injectiondialog I have the following I have the following listed:

/****************************************************************************
** Meta object code from reading C++ file 'injectiondialog.h'
**
** Created: Sat Jan 7 21:58:22 2012
**      by: The Qt Meta Object Compiler version 62 (Qt 4.7.4)
**
** WARNING! All changes made in this file will be lost!
*****************************************************************************/

#include "../InjectionGUI/injectiondialog.h"
#if !defined(Q_MOC_OUTPUT_REVISION)
#error "The header file 'injectiondialog.h' doesn't include <QObject>."
#elif Q_MOC_OUTPUT_REVISION != 62
#error "This file was generated using the moc from 4.7.4. It"
#error "cannot be used with the include files from this version of Qt."
#error "(The moc has changed too much.)"
#endif

QT_BEGIN_MOC_NAMESPACE
static const uint qt_meta_data_InjectionDialog[] = {

 // content:
       5,       // revision
       0,       // classname
       0,    0, // classinfo
       2,   14, // methods
       0,    0, // properties
       0,    0, // enums/sets
       0,    0, // constructors
       0,       // flags
       0,       // signalCount

 // slots: signature, parameters, type, tag, flags
      17,   16,   16,   16, 0x08,
      29,   16,   16,   16, 0x08,

       0        // eod
};

static const char qt_meta_stringdata_InjectionDialog[] = {
    "InjectionDialog\0\0checkData()\0"
    "checkFluidVelocity()\0"
};

const QMetaObject InjectionDialog::staticMetaObject = {
    { &QDialog::staticMetaObject, qt_meta_stringdata_InjectionDialog,
      qt_meta_data_InjectionDialog, 0 }
};

#ifdef Q_NO_DATA_RELOCATION
const QMetaObject &InjectionDialog::getStaticMetaObject() { return staticMetaObject; }
#endif //Q_NO_DATA_RELOCATION

const QMetaObject *InjectionDialog::metaObject() const
{
    return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject;
}

void *InjectionDialog::qt_metacast(const char *_clname)
{
    if (!_clname) return 0;
    if (!strcmp(_clname, qt_meta_stringdata_InjectionDialog))
        return static_cast<void*>(const_cast< InjectionDialog*>(this));
    return QDialog::qt_metacast(_clname);
}

int InjectionDialog::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QDialog::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: checkData(); break;
        case 1: checkFluidVelocity(); break;
        default: ;
        }
        _id -= 2;
    }
    return _id;
}
QT_END_MOC_NAMESPACE

I have looked over some of the other moc_file posts and most of them say to have Qt clean and rebuild the project. I have ran a project clean up and rebuild all to try to overhaul this moc file but have not had any success in getting rid of the error. It seems like a bug but I couldn't find anything online about it so maybe it's something I don't know about. Thanks in advance for any help you can offer.

Was it helpful?

Solution

Whenever I have MOC problems, I Build->Clean All and then Build->Run qmake (Qt Creator IDE). If that doesn't solve my problem, I go into my project folder and delete moc_* files and any other junk that Clean doesn't remove - basically leaving nothing but headers, source and resources.

OTHER TIPS

Go to you moc file which is throwing the error. At the top, there will be an include statement, which includes the header file for that window, NOT ui_.h, just .h check in that file if there is a reference to the widget which is causing the error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top