gpt4 book ai didi

c++ - moc 文件中缺少信号槽

转载 作者:行者123 更新时间:2023-11-28 01:45:35 26 4
gpt4 key购买 nike

我无法使用已连接到正确插槽的按钮。

这里是 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()
{

}

这里是依赖的.h文件:

#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

至少,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

在应用程序运行期间,我收到以下消息:

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')

我在其他线程中读到,moc 文件负责在信号和槽之间创建“关系”。

但是 moc 文件不包含任何信号槽列表。我知道,它必须包含类似 qt_meta_data_InfoPage[] 中的内容:

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

0 //end

如果我删除 moc 文件的内容,新生成的 moc 文件包含相同的代码。

是否可以手动将信号/槽添加到 moc 文件中?

问候,

萨米尔

最佳答案

moc文件中缺少槽的原因是这两个方法没有声明为槽,它们被声明为简单方法:

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

相反,它们应该声明为插槽:

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

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

关于c++ - moc 文件中缺少信号槽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45276397/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com