我有一个QListWidget,位于QWizardPage中的QGridLayout中。 QListWidget中的项目是目录中的所有xml文件。我有一切工作,但信号。我错过了一些关键而且简单的东西,我确定。
我查看了QListWidget文档以及this和this帖子等。一切似乎都说itemClicked(QListWidgetItem *)应该是我需要的,但它和其他人都没有工作,即我的函数new_sequence_selected永远不会被调用。 Connect也永远不会为此返回句柄,总是错误的。
我尝试过的大部分信号都在下面的代码中。
我的browseButton工作正常。
其他信息:在Win7,VS2012,Qt5,Qt VS插件1.2.2中工作
提前感谢您的帮助!!
creator.h
#include <qwizard.h>
#include <QtWidgets>
#include <QHeaderView>
class Sequence_selectPage : public QWizardPage
{
Q_OBJECT
public: Sequence_selectPage( QWidget *parent = 0 );
private slots:
void browse();
private:
QListWidget *sequenceList;
QDir sequences_dir_path;
QString selected_sequence;
};
creator.cpp
#include "creator.h"
Sequence_selectPage::Sequence_selectPage( QWidget *parent ) : QWizardPage( parent )
{
first_round = true;
setTitle( tr( "Select an xml" ) );
// setup path to Sequence
sequences_dir_path.absolutePath();
sequences_dir_path.cd( "Sequence" );
//set up the list for the files
sequenceList = new QListWidget( this );
//sequenceList->setSelectionMode( QAbstractItemView::SingleSelection );
QStringList filter;
filter << "*.xml";
//add xmls to list
foreach( QString File, sequences_dir_path.entryList( filter, QDir::Files ) ) //(QStringList)"*.xml"
{
sequenceList->addItem( File );
}
if( sequenceList->count() > 0 )
{
sequenceList->item( 0 )->setSelected( true );
}
browseButton = buttonBuilder( tr( "Browse..." ), this, SLOT( browse() ) );
/*********** Figure out this signal **********/
connect( sequenceList, SIGNAL( sequenceList->itemClicked( QListWidgetItem* i ) ), this, SLOT( new_sequence_selected( QListWidgetItem* i) ) );
//connect( sequenceList, SIGNAL( itemClicked( QListWidgetItem* ) ), this, SLOT( new_sequence_selected( QListWidgetItem* ) ) );
//connect( sequenceList, SIGNAL( itemActivated( QListWidgetItem* ) ), this, SLOT( new_sequence_selected( QListWidgetItem* ) ) );
//connect( sequenceList, SIGNAL( itemEntered( QListWidgetItem* ) ), this, SLOT( new_sequence_selected( QListWidgetItem* ) ) );
//connect( sequenceList, SIGNAL( itemPressed( QListWidgetItem* ) ), this, SLOT( new_sequence_selected( QListWidgetItem* ) ) );
//connect( sequenceList, SIGNAL( itemSelectionChanged( ) ), this, SLOT( new_sequence_selected( ) ) );
//connect( sequenceList, SIGNAL( itemDoubleClicked( QListWidgetItem* ) ), this, SLOT( new_sequence_selected( QListWidgetItem* ) ) );
//connect( sequenceList, SIGNAL( itemChanged( QListWidgetItem* ) ), this, SLOT( new_sequence_selected( QListWidgetItem* ) ) );
//connect( sequenceList, SIGNAL( currentItemChanged( QListWidgetItem*, QListWidgetItem* ) ), this, SLOT( new_sequence_selected( QListWidgetItem* ) ) );
selectpageLayout = new QGridLayout( this );
selectpageLayout->addWidget( sequenceList, 0, 0, 1, 2 );
selectpageLayout->addWidget( browseButton, 1, 1 );
setLayout( selectpageLayout );
}
void Sequence_selectPage::new_sequence_selected( QListWidgetItem* sequence )
{
selected_sequence = sequence->text();
}
buttonBuilder代码
QPushButton *buttonBuilder( QString &button_name, QObject *receiver, const char *member )
{
QPushButton *mybutton = new QPushButton( button_name );
QObject::connect( mybutton, SIGNAL( clicked() ), receiver, member );
return mybutton;
}
答案 0 :(得分:1)
您没有将new_sequence_selected
声明为广告位。
试试这个:
#include <qwizard.h>
#include <QtWidgets>
#include <QHeaderView>
class Sequence_selectPage : public QWizardPage
{
Q_OBJECT
public: Sequence_selectPage( QWidget *parent = 0 );
private slots:
void browse();
void new_sequence_selected( QListWidgetItem* sequence ); //<-- ADDED THIS
private:
QListWidget *sequenceList;
QDir sequences_dir_path;
QString selected_sequence;
};