そのように定義されたQObjectサブクラスがあります(「Danbooru」名前空間内):
#ifndef DANBOORUPOST_H
#define DANBOORUPOST_H
// Qt
#include <QtCore/QObject>
#include <QtCore/QVariant>
#include <QtCore/QStringList>
#include <QtXml/QXmlStreamAttributes>
// KDE
#include <kurl.h>
class QPixmap;
namespace Danbooru {
class DanbooruPost : public QObject
{
Q_OBJECT
Q_PROPERTY(QPixmap* pixmap READ pixmap WRITE setPixmap)
Q_PROPERTY(int id READ id)
Q_PROPERTY(KUrl fileUrl READ fileUrl)
Q_PROPERTY(QStringList tags READ tags)
Q_PROPERTY(KUrl thumbnailUrl READ thumbnailUrl)
private:
QPixmap* m_pixmap;
// basic features of a post
int m_id;
int m_height;
int m_width;
int m_size;
KUrl m_url;
KUrl m_thumbnailUrl;
QStringList m_tags;
public:
explicit DanbooruPost(QVariantMap postData, QPixmap* pixmap = 0,
QObject* parent = 0);
explicit DanbooruPost(QXmlStreamAttributes& postData,
QPixmap* pixmap = 0, QObject* parent=0);
bool operator==(const DanbooruPost&);
~DanbooruPost();
// Post attributes
int id() const;
int height() const;
int width() const;
int size() const;
const KUrl fileUrl() const;
QStringList tags() const;
const KUrl thumbnailUrl() const;
QPixmap* pixmap() const;
void setPixmap(QPixmap* pixmap);
const QString toString();
};
}; // namespace Danbooru
Q_DECLARE_METATYPE(Danbooru::DanbooruPost*)
#endif // DANBOORUPOST_H
そして私はこのように定義された別のクラスでそれを使用しています:
#ifndef DANBOORUSERVICE_H
#define DANBOORUSERVICE_H
#include <QtCore/QObject>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <KUrl>
#include <KIO/JobClasses>
class QPixmap;
class KUrl;
class KJob;
class DanbooruPost;
namespace Danbooru {
enum TagType {
General,
Artist,
Copyright,
Character
};
using KIO::StoredTransferJob;
class DanbooruService : public QObject
{
Q_OBJECT
private:
// URL fragments
static const QString POST_URL;
static const QString TAG_URL;
static const QString POOL_URL;
static const QString ARTIST_URL;
static const QString POOL_DATA_URL;
static const QString RELATED_TAG_URL;
// member variables
KUrl m_url;
QString m_username;
QString m_password;
QStringList m_blacklist;
QString m_maxRating;
public:
DanbooruService(KUrl& boardUrl, QString username = QString(),
QString password = QString(),
QStringList blacklist = QStringList(),
QObject* parent=0);
~DanbooruService();
void getPostList(int page=1, QStringList tags=QStringList(),
int limit=100, QString rating="Safe");
void getPoolList(int page=0);
void getPool(int poolId, int page=1, QString rating="Safe");
void getTagList(int limit=10, QString name="");
void getRelatedTags(QStringList tags=QStringList(),
TagType tag_type=General);
QString allowedRating() const;
QStringList blacklist() const;
private Q_SLOTS:
void processPostList(StoredTransferJob* job);
void processPoolList(StoredTransferJob* job);
void processRelatedTagList(StoredTransferJob* job);
void downloadThumbnail(StoredTransferJob* job);
void downloadAllTags(StoredTransferJob* job);
Q_SIGNALS:
void postDownloadFinished();
void poolDownloadFinished();
void downloadError(QString error);
void postDownloaded(DanbooruPost*&post);
void postMetadataDownloaded(DanbooruPost* post);
// TODO: Tags and similar
};
};
私が経験している問題は、このコードから発生します(StoredTransferJobはKDEクラスです):
void DanbooruService::downloadThumbnail(StoredTransferJob* job)
{
if (job->error()) {
Q_EMIT(downloadError(job->errorString()));
}
QVariant postData = job->property("danbooruPost");
DanbooruPost* post = (DanbooruPost*) postData.data();
QPixmap* pix = new QPixmap();
bool ok = pix->loadFromData(job->data());
if (!ok) {
Q_EMIT(downloadError(QString("Pixmap data could not be loaded")));
}
post->setPixmap(pix);
Q_EMIT(postDownloaded(post));
}
ただし、コンパイルすると、Q_EMIT部分は次のエラーを生成します。
/home/lb/Coding/cpp/danbooru_client/src/libdanbooru/danbooruservice.cpp: In member function ‘void Danbooru::DanbooruService::downloadThumbnail(KIO::StoredTransferJob*)’:
/home/lb/Coding/cpp/danbooru_client/src/libdanbooru/danbooruservice.cpp:186:35: error: no matching function for call to ‘Danbooru::DanbooruService::postDownloaded(Danbooru::DanbooruPost*&)’
/home/lb/Coding/cpp/danbooru_client/src/libdanbooru/danbooruservice.cpp:186:35: note: candidate is:
In file included from /home/lb/Coding/cpp/danbooru_client/src/libdanbooru/danbooruservice.cpp:30:0:
/home/lb/Coding/cpp/danbooru_client/src/libdanbooru/danbooruservice.h:104:14: note: void Danbooru::DanbooruService::postDownloaded(DanbooruPost*&)
/home/lb/Coding/cpp/danbooru_client/src/libdanbooru/danbooruservice.h:104:14: note: no known conversion for argument 1 from ‘Danbooru::DanbooruPost*’ to ‘DanbooruPost*&’
関数で使用されるバリアントを生成するコードは次のとおりです。
void DanbooruService::processPostList(KIO::StoredTransferJob* job)
{
qDebug() << "Got data OK";
if (job->error()) {
Q_EMIT(downloadError(job->errorString()));
}
QByteArray data = job->data();
QJson::Parser parser;
bool ok;
QVariant result = parser.parse(data, &ok);
if (!ok) {
Q_EMIT(downloadError(QString("Unable to decode data")));
}
QList<QVariant> postList = result.toList();
Q_FOREACH(QVariant element, postList) {
QVariantMap map = element.toMap();
DanbooruPost* post = new DanbooruPost(map);
StoredTransferJob* pixmapJob = KIO::storedGet(post->thumbnailUrl(),
KIO::NoReload, KIO::HideProgressInfo);
qDebug() << "Basic job info";
qDebug() << post->id() << post->thumbnailUrl() << post->fileUrl();
QVariant variant;
variant.setValue(post);
pixmapJob->setProperty("danbooruPost", variant);
connect(pixmapJob, SIGNAL(result(KJob*)), this,
SLOT(downloadThumbnail(StoredTransferJob*)));
}
私はこのエラーに完全に困惑しています。私は何を間違っているのでしょうか?