C++ 无法生成Qt自定义小部件
我正试图制作一个定制的小部件/插件,由Qt设计器将其解释为拖放元素。但是,大多数工作在构建结束时都会出现一个错误。无法将参数1从'QWidget*'转换为'const glieneedit&'我不太确定这需要我做什么来修复它,但也不太确定。以下是我的相关源代码: GlineEditPlugin.cpp代码段C++ 无法生成Qt自定义小部件,c++,qt,qt-designer,C++,Qt,Qt Designer,我正试图制作一个定制的小部件/插件,由Qt设计器将其解释为拖放元素。但是,大多数工作在构建结束时都会出现一个错误。无法将参数1从'QWidget*'转换为'const glieneedit&'我不太确定这需要我做什么来修复它,但也不太确定。以下是我的相关源代码: GlineEditPlugin.cpp代码段 QWidget *GLineEditPlugin::createWidget(QWidget *parent) { return new GLineEdit(parent); }
QWidget *GLineEditPlugin::createWidget(QWidget *parent)
{
return new GLineEdit(parent);
}
glieneedit.cpp
#include "glineedit.h"
GLineEdit::GLineEdit(const QString &str, const QString &color, QWidget *parent)
: QWidget(parent)
{
QVBoxLayout *layoutMain = new QVBoxLayout(this);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
m_header = new GLineEditHeader(this, str);
m_header->setStyleSheet("QLabel { color: " + color + "; }");
m_input = new GLineEditInput(this);
m_input->setStyleSheet(QString("QLineEdit { font-size: 12pt; padding-bottom: 5px; border: none; background-color: transparent; border-bottom: 2px solid %1; color: %1;}").arg(color));
layoutMain->addSpacerItem(new QSpacerItem(20, 15, QSizePolicy::Minimum, QSizePolicy::Fixed));
layoutMain->addWidget(m_input);
layoutMain->setContentsMargins(0, 0, 0, 0);
layoutMain->setSpacing(0);
connect(m_input, &GLineEditInput::focusChanged, m_header, &GLineEditHeader::zoom);
connect(m_input, &GLineEditInput::cleared, m_header, &GLineEditHeader::enableZoom);
}
我需要它
#ifndef GLINEEDIT_H
#define GLINEEDIT_H
#include "glineeditheader.h"
#include "glineeditinput.h"
#include <QWidget>
#include <QVBoxLayout>
class GLineEdit : public QWidget
{
Q_OBJECT
public:
GLineEdit(const QString &str, const QString &color, QWidget *parent = 0);
QString text() const;
QString title() const;
void setText(const QString &str);
void setTitle(const QString &str);
private:
GLineEditHeader *m_header;
GLineEditInput *m_input;
};
#endif //GLINEEDIT_H
这不是一个问题,你没有指出失败的地方
但是,您的问题很可能可以在这里找到:
return new GLineEdit(parent);
您的类GLineEdit不提供接受QWidget*类型的单个参数的构造函数,而只提供接受多个参数的构造函数。因此编译器尝试使用自动创建的复制构造函数,如下所示
GLineEdit::GLineEdit(const GLineEdit&)
可能的解决办法:
将缺少的参数添加到构造函数调用中。
提供一个构造函数,该构造函数接受指向父窗口小部件的指针作为唯一参数。
哪一行与错误关联?我在代码中没有看到任何地方需要const glieneedit&类型的变量。您的代码不完整,也不是最小值。您应该能够创建一个更简单的示例,其中包括插件注册,并且不需要GLineEditInput,不管是什么。请输入您的代码,使其成为您问题的一部分,然后我们可以尝试复制并解决它。你也应该阅读。