c++qtqt-designer

Qt Custom Widget Failing to Build


I am attempting to make a custom widget/plugin to be interpreted by Qt Designer as a drag and drop element. Most works however I do get one error at the end of the build. Cannot convert argument 1 from 'QWidget *' to 'const GLineEdit &' I'm not too sure what this wants me to do to fix it, but not much is too sure. Here is my relevant source code:

GlineEditPlugin.cpp Snippet

QWidget *GLineEditPlugin::createWidget(QWidget *parent)
{
    return new GLineEdit(parent);
}

GLineEdit.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);
}

GLineEdit.h

#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

Solution

  • Your problem can be found here:

    return new GLineEdit(parent);
    

    Your class GLineEdit doesn't provide a constructor that takes a single argument of type QWidget*, only one that accepts multiple arguments. So the compiler tries to resort to the automatically created copy constructor, which looks like

    GLineEdit::GLineEdit(const GLineEdit&)
    

    Possible solutions:

    1. Add the missing parameters to your constructor call.
    2. Provide a constructor that accepts a pointer to a parent widget as only parameter.