0
#ifndef FF_H
#define FF_H
#include <QtQuick/QQuickPaintedItem>
#include "qpainter.h"
#include <QQuickItem>
#include <QQuickWindow>
class Draw_on_qimage : public QQuickPaintedItem
{
Q_OBJECT
public:
virtual void paint(QPainter *);
Draw_on_qimage(QQuickPaintedItem *parent = 0);
public slots:
void setbb_list(QList<bounding_box_struct> bb_list)
{
for (int h = 0; h < bb_list.size(); h++)
{
bounding_box_struct obj;
obj.x = bb_list[h].x;
m_bb_list.push_back(obj);
}
emit bb_listChanged(m_bb_list);
}
protected:
virtual void componentComplete();
private:
struct bounding_box_struct
{ int x;
int y;
int w;
int h;
std::string vehicle_type;
};
Q_PROPERTY(QList<bounding_box_struct> bb_list
READ bb_list
WRITE setbb_list
NOTIFY bb_listChanged)
QList<bounding_box_struct> m_bb_list;
signals:
void bb_listChanged(QList<bounding_box_struct> bb_list);
};
#endif // FF_H
bb_list
は、Q_PROPERTY
である必要があります。あなたはそれを使用する前に、構造体を定義する必要がありますQtのクラスで宣言された構造体を同じクラスの関数に渡すにはどうすればいいですか?
error: ‘bounding_box_struct’ was not declared in this scope
void setbb_list(QList<bounding_box_struct> bb_list)
^
error: request for member ‘size’ in ‘bb_list’, which is of non-class type ‘int’
for (int h = 0; h < bb_list.size(); h++)
^
error: invalid types ‘int[int]’ for array subscript
obj.x = bb_list[h].x;
^
おかげ:
はまた、あなたは、クラス定義の外で、あなたのメソッドの実装を置けば、あなたは完全に戻り値の型に構造体を修飾する必要がありますが、それはパラメータではオプションだということに注意してください。 –