2017-11-23 10 views
0

ユーザーインターフェイスのコードを開発する際に問題が発生しています。私はYoctoを配備したLinuxディストリビューションでQt 4.8を使用しています。ここ 私のコードの本当に簡単なスニペット:'QAbstractItemViewPrivate'値の仮想テーブルのリンカシンボルが見つかりません

// 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()); 
} 

すべてがうまくいきます!だから、それは私にスロットコールを「終了」することに関連しているようです。他のいくつかのテストをした後、あなたの助け

答えて

0

ため

多くのおかげで、私は私が問題とどのようにそれを解決するためにである見つけたと思います。

ここでは、クラスParentによって使用されるクラスボタンがある、簡単なコードのスニペットです。 ボタンをクリックすると、パネルが変更されたり、メッセージが表示されたり、その他の操作が実行されたりすることがあります。

私は何を見つけることはスロットにクラスボタン onClickedさ:場合は、最初のを入力し、プログラムは現在のパネル(およびそのチャイルズを削除するには、クラスパネルを引き起こす信号request_GoToPrevを発します、Buttonをコンパイルしても!)新しいものを作り上げる。 信号を出して必要なすべてのアクションを実行した後、プログラムは信号を出して命令の実行を続ける時点に戻ります。はそれ以上ではなく、がクラッシュした場合、2番目のに達します一貫している。

これは私のテスト後のようです。 の返信は、の問題が解決された場合、最初ののシグナル発信の直後に呼び出されます。

// 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... 
} 
関連する問題