I cannot use the button, which I have connected with the correct slot.
Here the infoPage.cpp file:
#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()
{
}
Here the depend .h file:
#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
At least, the moc file:
/****************************************************************************
** 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
During the run of the application, I get the following message:
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')
I have read in other threads, that the moc file is responsible to create a "relation" between the signal and slot.
But the moc file does not contain any list of signal slots. I know, it has to contain something like that in qt_meta_data_InfoPage[]:
// slots: signature, parameters, type, tag, flags
10, 9, 9, 9, 0x08,
54, 50, 9, 9, 0x08,
0 //end
If I removes the content of the moc file, the new generated moc file contains the same code.
Is there any possibility to add the signal/slot to the moc file manually?
Regards,
Samir
The reason for the lack of slots in the moc file is the fact that the two methods are not declared as slots, they are declared as simple methods:
public:
InfoPage(QWidget *parent = 0);
~InfoPage();
void openReleaseNotes();
void closeInfoPage();
Instead, they should be declared as slots:
public:
InfoPage(QWidget *parent = 0);
~InfoPage();
public slots:
void openReleaseNotes();
void closeInfoPage();