我有两个类:HoodPlanner和DrawRoad。这两个类都继承自QWidget和UI,因此我可以访问这两个类中的所有UI元素。
这是两个类的剪辑:
HoodPlanner:
#ifndef HOODPLANNER_H
#define HOODPLANNER_H
#include <ui_hoodplanner.h>
#include "drawroad.h"
#include <QtWidgets>
class HoodPlanner : public QWidget, private Ui::HoodPlanner
{
Q_OBJECT
private:
// (...)
public:
explicit HoodPlanner(QWidget * = 0);
// (...)
private slots:
// (...)
};
#endif // HOODPLANNER_H
DrawRoad:
#ifndef DRAWROAD_H
#define DRAWROAD_H
#include <ui_hoodplanner.h>
#include <QtWidgets>
class DrawRoad : public QWidget, private Ui::HoodPlanner
{
Q_OBJECT
private:
// (...)
public:
explicit DrawRoad(QWidget *parent = 0);
public slots:
void drawSC4Street();
};
#endif // DRAWROAD_H
在HoodPlanner中,每当itemSelection在table_ts2中发生更改时,我都会发出一个连接。我将插槽存储在DrawRoad中,但是在第三个位置插入DrawRoad对象的引用会带来错误。
HoodPlanner::HoodPlanner(QWidget *parent) : QWidget(parent)
{
setupUi(this);
// (...)
DrawRoad *drawRoad = new DrawRoad;
connect(table_ts2, SIGNAL(itemSelectionChanged()), &drawRoad, SLOT(drawSC4Street()));
}
从DrawRoad.cpp剪掉:
#include "drawroad.h"
DrawRoad::DrawRoad(QWidget *parent) : QWidget(parent)
{
}
void DrawRoad::drawSC4Street()
{
if(!table_ts2->selectionModel()->hasSelection()) return;
// (...)
}
每当我运行应用程序时都会出现以下错误:
hoodplanner.cpp:12: Fehler: no matching function for call to 'HoodPlanner::connect(QTableWidget*&, const char [24], DrawRoad**, const char [17])'
mingw492_32\include\QtCore\qobject.h:213: Fehler: no type named 'Object' in 'struct QtPrivate::FunctionPointer<const char*>'
(和很多笔记)
错误根本没有帮助我,我在几个主题中搜索了一个解决方案,但没有一个问题。
答案 0 :(得分:2)
你试过吗
HoodPlanner::HoodPlanner(QWidget *parent) : QWidget(parent)
{
setupUi(this);
// (...)
DrawRoad *drawRoad = new DrawRoad;
connect(table_ts2, SIGNAL(itemSelectionChanged()), drawRoad, SLOT(drawSC4Street()));
}
你将declrared drawRoad作为指针:
DrawRoad *drawRoad = new DrawRoad;
然后将其地址传递给connect()和&amp; drawRoad。
在这种情况下,您将指针传递给指针地址。尝试不使用&