こんにちは、QList をパラメーターとして別のクラスに送信しようとしていますが、何らかの理由で読み取りアクセス違反が発生しました...
CompareTimeChannel.h
class CompareTimeChannel : public IDataChannel
public:
// @brief The method used to receive the list
void setData(const QList< QSharedPointer<core::ITrackSection> > & sections);
// @brief The list
QList< QSharedPointer<core::ITrackSection> > _sections;
};
CompareTimeChannel.cpp
// @brief Empty constructor
CompareTimeChannel::CompareTimeChannel()
{
}
void CompareTimeChannel::setData(const QList< QSharedPointer<core::ITrackSection> > & sections)
{
//_sections = *new QList< QSharedPointer<core::ITrackSection> > ();
_sections.clear();
_sections.append(sections);
}
このコードを実行すると、スローException at 0x31cc78d, code: 0xc0000005: read access violation at: 0x4, flags=0x0
されます_sections.clear();
前にリストを初期化しようとしましたが (コメント行_sections = *new QList<...>
)、例外は同じようにスローされます。
答えは非常に高く評価されます...
編集
よし、直った!
まず、@AndreasT が言ったように、デフォルトの QList コンストラクターを初期化する必要がありました。
次に、@ 10WaRRioR01 の回答によるとCompareTimeChannel
、メソッドが最初に呼び出されたときに初期化されなかったことが問題の原因です。を使用して修正:
CompareTimeChannel* chan = static_cast<CompareTimeChannel*>(channel);
Q_ASSERT(chan);
if (chan) {
chan->setData(sections);
}
else {
qDebug() << "Dynamic cast failure";
}
みんなありがとう!