2017-07-24 3 views
0

Je ne peux pas utiliser le bouton, que j'ai connecté avec l'emplacement correct.L'emplacement de signal est manquant dans le fichier moc

Voici le fichier infoPage.cpp:

#include "infoPage.h" 

InfoPage::InfoPage(QWidget *parent) 
    : QDialog(parent) 
{ 
    ui.setupUi(this); 
    bool working = false; 
    working = QObject::connect(ui.b_showReleaseNotes, SIGNAL(clicked()), this, SLOT(openReleaseNotes())); 
    working = QObject::connect(ui.ok_button, SIGNAL(clicked()), this, SLOT(closeInfoPage())); 
} 

void InfoPage::openReleaseNotes() 
{ 

    QString prog = "C:\\Windows\\System32\\"; 

    const char *args[3]; 

    //get full path of file to use it in cmd 

    QString currentAppPath = QCoreApplication::applicationDirPath(); 

    QString releaseNotePath = currentAppPath + "release_notes.txt"; 

    args[0] = "notepad.exe"; 
    args[1] = _strdup(releaseNotePath.toAscii()); 
    args[2] = NULL; 

    prog += args[0]; 
    //LOG_DEBUG("starting external program '%s' with file '%s'", prog.toAscii(), docPath.toAscii()); 

    int errorCode = _spawnv(_P_NOWAIT , _strdup(prog.toAscii()),args); 

    if (errorCode == -1) 
    { 
     QMessageBox::information(NULL, "Error:","An error occured while starting process. The call was\n\""+prog+" "+releaseNotePath+"\""); 
    } 


} 

void InfoPage::closeInfoPage() 
{ 
    QString test = "ABC"; 
    this->close(); 
    return; 
} 


InfoPage::~InfoPage() 
{ 

} 

Ici, le fichier .h dépendent:

#ifndef INFOPAGE_H 
#define INFOPAGE_H 

#include <QDialog> 
#include "ui_infoPage.h" 
#include <QProcess> 
#include <process.h> 
#include <QtDebug> 
#include <QtGui/QMessageBox> 

class InfoPage : public QDialog 
{ 

Q_OBJECT 


public: 
    InfoPage(QWidget *parent = 0); 
    ~InfoPage(); 
    void openReleaseNotes(); 
    void closeInfoPage(); 


//private: 
    Ui::InfoPage ui; 

private: 
    //void openReleaseNotes(); 
    QString programPath; 

}; 

#endif // INFOPAGE_H 

Au moins, le fichier moc:

/**************************************************************************** 
** Meta object code from reading C++ file 'infoPage.h' 
** 
** Created: Mon 24. Jul 10:41:32 2017 
**  by: The Qt Meta Object Compiler version 62 (Qt 4.7.0) 
** 
** WARNING! All changes made in this file will be lost! 
*****************************************************************************/ 

#include "../../infoPage.h" 
#if !defined(Q_MOC_OUTPUT_REVISION) 
#error "The header file 'infoPage.h' doesn't include <QObject>." 
#elif Q_MOC_OUTPUT_REVISION != 62 
#error "This file was generated using the moc from 4.7.0. 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_InfoPage[] = { 

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

     0  // eod 
}; 

static const char qt_meta_stringdata_InfoPage[] = { 
    "InfoPage\0" 
}; 

const QMetaObject InfoPage::staticMetaObject = { 
    { &QDialog::staticMetaObject, qt_meta_stringdata_InfoPage, 
     qt_meta_data_InfoPage, 0 } 
}; 

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

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

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

int InfoPage::qt_metacall(QMetaObject::Call _c, int _id, void **_a) 
{ 
    _id = QDialog::qt_metacall(_c, _id, _a); 
    if (_id < 0) 
     return _id; 
    return _id; 
} 
QT_END_MOC_NAMESPACE 

Au cours de la course de l'application, je reçois le message suivant:

Object::connect: No such slot InfoPage::openReleaseNotes() in infoPage.cpp:8 
Object::connect: (sender name: 'b_showReleaseNotes') 
Object::connect: (receiver name: 'InfoPage') 
Object::connect: No such slot InfoPage::closeInfoPage() in infoPage.cpp:9 
Object::connect: (sender name: 'ok_button') 
Object::connect: (receiver name: 'InfoPage') 

J'ai lu dans d'autres threads, que le fichier moc est responsable de créer une "relation" entre le signal et l'emplacement.

Mais le fichier moc ne contient aucune liste d'emplacements de signaux. Je sais, il doit contenir quelque chose comme ça dans qt_meta_data_InfoPage []:

// slots: signature, parameters, type, tag, flags 
     10, 9, 9, 9, 0x08, 
     54, 50, 9, 9, 0x08, 

    0 //end 

Si je supprime le contenu du fichier moc, le nouveau fichier moc généré contient le même code.

Est-il possible d'ajouter manuellement le signal/emplacement au fichier moc?

Cordialement,

Samir

+1

Vous devez déclarer 'openReleaseNo tes() 'et' closeInfoPage() 'en tant que tels, c'est-à-dire utiliser' public slots: 'spécificateur dans votre déclaration de classe au lieu de' public '. – vahancho

Répondre

2

La raison de l'absence de créneaux horaires dans le fichier moc est le fait que les deux méthodes ne sont pas déclarés comme créneaux horaires, ils sont déclarés comme des méthodes simples:

public: 
    InfoPage(QWidget *parent = 0); 
    ~InfoPage(); 
    void openReleaseNotes(); 
    void closeInfoPage(); 

au lieu de cela, ils doivent être déclarés comme créneaux horaires:

public: 
     InfoPage(QWidget *parent = 0); 
     ~InfoPage(); 

public slots: 
     void openReleaseNotes(); 
     void closeInfoPage();