Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Qt signal connect failing
Forum Updated to NodeBB v4.3 + New Features

[Solved] Qt signal connect failing

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    progAK
    wrote on last edited by
    #1

    I have a QListWidget that is in a QGridLayout within a QWizardPage. The items in the QListWidget are all of the xml files in a directory. I have everything working but for the signals. I missing something critical but simple I'm sure.

    I've looked at the "QListWidget":http://qt-project.org/doc/qt-4.8/qlistwidget.html documentation and at "this":http://stackoverflow.com/questions/15311241/qlistwidget-event-on-item-click and "this":http://stackoverflow.com/questions/7008611/detecting-if-an-item-is-clicked-at-at-some-row-in-a-qlistwidget post, among others. Everything seems to say itemClicked( QListWidgetItem* ) should be what I need but it and others aren't working i.e. my function new_sequence_selected is never getting called. Connect is also never returning a handle for this, always false.

    Most of the signals I've tried are in the code below.

    Also my browseButton is working just fine.

    Additional info: Working in Win7, VS2012, Qt5, Qt VS Add-in 1.2.2

    Thanks in advance for the help!!

    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 code
    @
    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;
    }@

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Your connect statement is wrong:

      @
      connect(sequenceList, SIGNAL( sequenceList->itemClicked( QListWidgetItem* i ) ), this, SLOT( new_sequence_selected( QListWidgetItem* i) ) );@

      would be
      @
      connect(sequenceList, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(new_sequence_selected(QListWidgetItem*)));

      Or in this case

      connect(sequenceList, SIGNAL(itemClicked(QListWidgetItem*)), SLOT(new_sequence_selected(QListWidgetItem*)));
      @

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • P Offline
        P Offline
        progAK
        wrote on last edited by
        #3

        The problem ultimately being that I hadn't declared new_sequence_selected( QListWidgetItem* i) as a slot. With that done
        @
        connect( sequenceList, SIGNAL( itemClicked(QListWidgetItem* ) ), this, SLOT( new_sequence_selected( QListWidgetItem* ) ) );
        @

        returns a handle as it should.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved