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] Subclass QHeaderView.
Forum Updated to NodeBB v4.3 + New Features

[Solved] Subclass QHeaderView.

Scheduled Pinned Locked Moved General and Desktop
qheaderviewinheritanceqtableviewsubclassing
3 Posts 2 Posters 2.6k Views 2 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.
  • S Offline
    S Offline
    SwePtr
    wrote on last edited by SwePtr
    #1

    I need to manipulate use signal from QHeaderView to bind some actiions.
    This is working . Here I Defined the slot in my mainclass.

    filemanager.h
    [code] void sectionClicked( int index);
    [/code]

    filemanager.cpp
    [code]QObject::connect( ui->treeView->header (),SIGNAL( sectionClicked( int ) ), this, SLOT(HDA->sectionClicked(int)));
    .....
    void FileManager:::sectionClicked( int index)
    {
    QMessageBox::about(this,"Header Click Detected!"
    ,"Index:"+QString::number(index));
    }[/code]

    When I try to put the code for sectionClicked in a separate class, it either not compiles
    as soon I am trying to define a pointer to that class. As I understand it should be because Q_OBJECTneeds to be declared in that class.

    Without Q_OBJECT, no problem with compilation - but the function will never execute.

    Is there any workarounds.?

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      QObject::connect( ui->treeView->header (),SIGNAL( sectionClicked( int ) ), this, SLOT(HDA->sectionClicked(int)));

      If HDA is the name of class that has sectionClicked slot then this should be:

      HDA* hda = ... // instance of HDA class
      QObject::connect( ui->treeView->header(), SIGNAL( sectionClicked( int ) ), hda, SLOT(sectionClicked(int)));
      

      If you want to connect a slot then that slot needs to be defined. You can only define slots in QObject derived classes with Q_OBJECT macro used.

      But you can connect to anything callable, not just slots. So if sectionClicked(int) is a member function in class HDA then you can connect it like this too:

      HDA* hda = ... // instance of HDA class
      QObject::connect(ui->treeView->header(), &QHeaderView::sectionClicked, hda, &HDA::sectionClicked);
      
      1 Reply Last reply
      1
      • S Offline
        S Offline
        SwePtr
        wrote on last edited by
        #3

        Oh, I see. Thank you sir.

        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