找不到'QAbstractItemViewPrivate'值的虚拟表的链接器符号

can't find linker symbol for virtual table for 'QAbstractItemViewPrivate' value

本文关键字:链接 符号 QAbstractItemViewPrivate 找不到 虚拟      更新时间:2023-10-16

我在为用户界面开发代码时面临问题。我正在使用Yocto部署的Linux发行版上使用QT 4.8。这里是我的代码的真正简单片段:

//  MyWidget.h
class MyWidget : public QWidget
{
    Q_OBJECT
public:
    MyWidget( QWidget* parent );
    ~MyWidget();
signals:
    void request_GoToNext( QString );           //!< Go to next panel
private slots:
    void onNext( QModelIndex index );
private:
    QTableView          *tableView;          
    QStandardItemModel  *dataModel;              
}

//  MyWidget.cpp
MyWidget::MyWidget( QWidget *parent ) : QWidget(parent)
{
    this->tableView = new QTableView(this);
    this->dataModel = new QStandardItemModel();
    // "Fill-in" data model with the list of files in a specific directory
    ...
    connect( this->tableView, SIGNAL(clicked(QModelIndex)), this, SLOT(onNext(QModelIndex)), Qt::UniqueConnection );
}
MyWidget::~MyWidget()
{
    disconnect( this->tableView, SIGNAL(clicked(QModelIndex)), this, SLOT(onNext(QModelIndex)) );
    this->dataModel->clear();
    delete this->tableView;
    delete this->dataModel;
}
void MyWidget::onNext( QModelIndex index )
{
    emit this->request_GoToNext( this->dataModel->item(index.row(), index.column())->text() );
}

问题在发出信号" request_gotonext"时具有起源,这会使应用程序崩溃或由于分段故障而导致的调试停止。我可以看到的是,在qtCreator中,该应用程序似乎失败的点是在文件qabstractitemview.cpp中,在此功能中更具体:

QStyleOptionViewItemV4 QAbstractItemViewPrivate::viewOptionsV4() const
{
    Q_Q(const QAbstractItemView);
    QStyleOptionViewItemV4 option = q->viewOptions();
    if (wrapItemText)
        option.features = QStyleOptionViewItemV2::WrapText;
    option.locale = q->locale();
    option.locale.setNumberOptions(QLocale::OmitGroupSeparator);
    option.widget = q;
    return option;
}

对我来说,这听起来真的很奇怪。发出信号后,该应用程序应删除当前面板并构建另一个面板:设置一些" Qdebug"调用,这似乎发生了,删除了当前面板(及其子女)并创建一个新的面板,但是该应用程序在显示新面板之前失败了。删除与mywidget相关的所有内容后,该程序似乎"退出"了插槽" onnext"。

另外,在qtCreator的TEH应用程序输出中,我可以阅读此消息

找不到" qabstractitemviewprivate"值的虚拟表的链接符号

nb-观察如果我以这种方式重写插槽内的代码

 void MyWidget::onNext( QModelIndex index )
 {
     QObject::startTimer(1);
     emit this->request_GoToNext( this->dataModel->item(index.row(), index.column())->text() );
 }
 void MyWidget::timerEvent( QTimerEvent *event )
 {
     QObject::killeTimer( event->timerId() );
     emit this->request_GoToNext( this->dataModel->item(index.row(), index.column())->text() );
 }

一切正常!这就是为什么它似乎与"退出"插槽呼叫我有关的原因。

非常感谢您的帮助

在其他一些测试之后,我认为我发现哪个是问题以及如何解决。

在这里,我的代码的简化片段,其中有一个类父母使用的类按钮。单击按钮时,它可能会导致面板更改,或提出消息或执行其他操作(与问题无关的详细措施)。

我发现的是slot class button 的关注:输入第一个如果,该程序发出信号 request_gotoprev <</em>/em>,这会导致类面板删除当前面板(及其子女,甚至包含了按钮!)并提高了一个新的。但是,在发出信号并执行所有需要的操作后,该程序"恢复"到发出信号并继续执行的点:当它到达第二个时,它是因为>这个不再是一致的。

这就是我的测试后的样子。如果解决问题,请在第一个中放置信号发射之后,将A 返回

// HEADER: Button.h
class Button : public QPushButton
{
    Q_OBJECT
public:
    Button( QWidget *parent = 0 );
    ~Button();
signals:
    void request_GoToPrev();                    //!< Go to previous panel
    void request_GoToNext( QString );           //!< Go to next panel
    void signal_Error( int );                   //!< Error code
private slots:
    void onClicked();
private:
    typ_Button_tags *widgetTags;                //!< Pointer to the tags structure that defines the ref Button widget
    typ_Shared      *privateCtx;                //!< Reference to runtime application structure
};
// C: Button.cpp
Button::Button( QWidget *parent )
    :
      QPushButton(parent)
{
    //  Do some settings, like: font, stylesheet, focus, size..
}
Button::~Button()
{
}
void Button::onClicked()
{
    //  Callback to be called when button clicked
    if( !this->widgetTags->callbackClick.isEmpty() )
    {
            emit this->request_GoToPrev();
            /*  !!! ATTENTION   !!!
             *
             *  Here the instruction return HAS to be written, otherwise the application crashes.
             *  In fact, when running, the signal 'request_GoToPrev' is sent, but the flow of the
             *  process should exit the call of this slot.
             *  Doing that, 'this' is no more consistent after having emitted the signal, so the
             *  application face a segmentation fault.
             */
            return;
    }

    //  Message box
    if( !this->widgetTags->msgText.isEmpty() )
    {
        //  Do some other actions on 'this'...
    }
}
// HEADER: Panel.h
class Panel : public QMainWindow
{
    Q_OBJECT
public:
    Panel( QWidget *parent = 0 );
private slots:
    void on_GoToNext(int index);
    void on_GoToPrevious();
    void on_Error(int errId);
private:
    Button *Btn;
};
// C: Panel.h
Panel::Panel( QWidget *parent )
    :
      QMainWindow(parent)
{
    //  Do some settings: font, stylesheet, focus, size...
    this->Btn = new Button( this );
        connect( this->Btn, SIGNAL(request_GoToPrev()), this, SLOT(on_GoToPrevious()), Qt::UniqueConnection );
    //  Do some actions to layout the button inside the panel
}
void Panel::on_GoToPrevious()
{  
    //  Do some check...
    delete this->Btn;
    //  Do some actions...
}