Qt - Can't find error on definition of TextEdit Item Delegate

Sunday, May 4, 2014

Well, the error that appears is the following



...\build-ChequesV2-Desktop_Qt_5_2_1_MinGW_32bit-Debug\debug\texteditdelegate.o:-1: In function `ZN16TextEditDelegateC2EP7QObject':

ChequesV2\texteditdelegate.cpp:8: error: undefined reference to `vtable for TextEditDelegate'
collect2.exe:-1: error: error: ld returned 1 exit status


I have read the code a lot of times, and I can't find where the error is, I have compared it with the codes of other 2 delegates and it seems to be all right.


here is the header:



#ifndef TEXTEDITDELEGATE_H
#define TEXTEDITDELEGATE_H

#include <QStyledItemDelegate>

class TextEditDelegate : public QStyledItemDelegate
{
Q_OBJECT

public:
TextEditDelegate(QObject *parent = 0);

QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const;

void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const;

};

#endif // TEXTEDITDELEGATE_H


And the implementation:



#include "texteditdelegate.h"

#include <QStyledItemDelegate>
#include <QInputDialog>



TextEditDelegate::TextEditDelegate(QObject *parent): QStyledItemDelegate(parent)
{

}

QWidget *TextEditDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &/* option */,
const QModelIndex &/* index */) const
{
QInputDialog *editor = new QInputDialog(parent);
editor->setOption(QInputDialog::UsePlainTextEditForTextInput);
editor->setInputMode(QInputDialog::TextInput);
editor->setLabelText("Ingrese el concepto del cheque");

return editor;
}


void TextEditDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
QString value = index.model()->data(index, Qt::EditRole).toString();

QInputDialog *inputDialog = static_cast<QInputDialog*>(editor);
inputDialog->setTextValue(value);
}


void TextEditDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
QInputDialog *inputDialog = static_cast<QInputDialog*>(editor);
if (!inputDialog) return;

model->setData(index, inputDialog->textValue()/*, Qt::EditRole*/);
}


and here is the call:



view = new QTableView;
view->setModel(tableProxy);
view->setItemDelegateForColumn(COLUMNADECONCEPTO, new TextEditDelegate(view));


Although commenting the last line changes nothing, the error still shows.







http://ift.tt/1q5jcMm