qApp->connect(header, &QHeaderView::sectionClicked, header, &ListIconHeaderClicked)
This is incorrect syntax for a connect() statement. The first half is OK - you are saying you want to connect to an instance of the QHeaderView class ("header") and its sectionClicked() signal. The second half is wrong for two reasons: first, if you want to handle that signal in some other class that you have implemented, then you put the instance pointer for that class as the third argument (not "header"); and second, the next argument must be the address of a method for the class you used as the third argument:
connect( header, &QHeaderView::sectionClicked, myClass, &MyClass::onSectionClicked ); // or whatever you call your class and slot
connect( header, &QHeaderView::sectionClicked, myClass, &MyClass::onSectionClicked ); // or whatever you call your class and slot
To copy to clipboard, switch view to plain text mode
Calling connect() through a qApp pointer is not necessary unless you are doing it from some code that is not in a class derived from QObject. QObject implements the connect() methods and all derived classes inherit them. Your slot definition should look like this:
class MyClass : public SomeClassDerivedFromQObject
{
Q_OBJECT
// constructor, destructor, etc.
public slots:
void onSectionClicked( int logicalIndex );
};
void MyClass::onSectionClicked( int logicalIndex )
{
// do whatever you want with the header and index.
// If you need the pointer to the QHeaderView:
if ( pView != nullptr )
{
// Safe to use the pView pointer
}
}
class MyClass : public SomeClassDerivedFromQObject
{
Q_OBJECT
// constructor, destructor, etc.
public slots:
void onSectionClicked( int logicalIndex );
};
void MyClass::onSectionClicked( int logicalIndex )
{
// do whatever you want with the header and index.
// If you need the pointer to the QHeaderView:
QHeaderView * pView = qobject_cast< QHeaderView * >( sender() );
if ( pView != nullptr )
{
// Safe to use the pView pointer
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks