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. QTreeView::doubleClicked not sending a signal
Forum Updated to NodeBB v4.3 + New Features

QTreeView::doubleClicked not sending a signal

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 1.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.
  • F Offline
    F Offline
    Fuchsiaff
    wrote on last edited by
    #1

    In my mainwindow.cpp class i have this connect function:
    QObject::connect(dir->view, &QTreeView::doubleClicked, this, &MainWindow::on_actionQuit_triggered);

    When double clicking on my QTreeView, the function isn't being run because the program didn't quit.

    Now when i move that connect function inside my Directory class, then it works and then it looks like this:
    QObject::connect(view, &QTreeView::doubleClicked, this, &Directory::open_file);

    So basically, dir->view and view should be the same thing but the problem is that the connect function in my mainwindow.cpp file just isn't being ran.

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

      Hi,

      Are you sure that dir->view is not a dangling pointer ? Because, for example, you shadowed it in your class constructor.

      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
      1
      • F Offline
        F Offline
        Fuchsiaff
        wrote on last edited by
        #3

        qDebug() << dir->view; returns QTreeView(0x354460)
        That means it shouldn't be a dangling pointer right?
        Also where do I shadow it in my class constructor, i searched for the word "dir" in all my files and only found this:
        dir = new Directory;

        1 Reply Last reply
        0
        • F Offline
          F Offline
          Fuchsiaff
          wrote on last edited by
          #4

          https://github.com/Fuchsiaff/PyPad_2
          My whole project can be found there, the place where i have problems can be found in
          Sources->mainwindow.cpp->line 37

          mrjjM 1 Reply Last reply
          0
          • F Fuchsiaff

            https://github.com/Fuchsiaff/PyPad_2
            My whole project can be found there, the place where i have problems can be found in
            Sources->mainwindow.cpp->line 37

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Fuchsiaff
            Hi
            You are not really inserting Directory into anything.
            So how do you try to db click it ?

            MainWindow::MainWindow(QWidget *parent) :
                QMainWindow(parent),
                ui(new Ui::MainWindow) {
                ui->setupUi(this);
            
                tab_class = new Tabs;
                dir = new Directory;
                dir->show(); // i added this and it shows up as other window as have no parent either
               ... 
                qDebug() << QObject::connect(dir->view, &QTreeView::doubleClicked, this, &MainWindow::on_actionQuit_triggered);
                setCentralWidget(tab_class);
            
            }
            

            so i think the main issu is you are not clicking on it ?

            1 Reply Last reply
            0
            • F Offline
              F Offline
              Fuchsiaff
              wrote on last edited by
              #6

              In my tabs.cpp file i have this function

                  dir_view->setVisible(true);
                  tab_layout->removeWidget(tab);
                  tab_layout->addWidget(dir_view->view);
                  tab_layout->addWidget(tab);
                  dir_view->hide();
              
              
                 // auto p = dynamic_cast<QMainWindow*>(parent());
              }
              

              and in mainwindow.cpp i have this:

              QObject::connect(test, &QShortcut::activated, tab_class, &Tabs::showDirectory);

              When i activate the shortcut, it pops open a directory inside the window and when double clicking on items on the directory then it shows no sign of working.

              Maybe that is the problem?

              mrjjM 1 Reply Last reply
              0
              • F Fuchsiaff

                In my tabs.cpp file i have this function

                    dir_view->setVisible(true);
                    tab_layout->removeWidget(tab);
                    tab_layout->addWidget(dir_view->view);
                    tab_layout->addWidget(tab);
                    dir_view->hide();
                
                
                   // auto p = dynamic_cast<QMainWindow*>(parent());
                }
                

                and in mainwindow.cpp i have this:

                QObject::connect(test, &QShortcut::activated, tab_class, &Tabs::showDirectory);

                When i activate the shortcut, it pops open a directory inside the window and when double clicking on items on the directory then it shows no sign of working.

                Maybe that is the problem?

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by mrjj
                #7

                @Fuchsiaff
                Hi
                kinda yes, you make a Directory object in mainwin and hook up its signal, but the one
                from

                class Tabs : public QWidget {
                    Q_OBJECT
                public:
                    explicit Tabs(QWidget *parent = nullptr);
                
                   ..
                 Directory *dir_view = new Directory(this, "C:"); <<< this is other one than one in main
                ...
                
                signals:
                
                public slots:
                    void showDirectory();
                
                private slots:
                    void tab_close_requested(int index);
                
                };
                

                so you didn't hook up its db click signal to anything.
                That was for the one you created in mainwindow. Not this one.
                so thats why nothing happens.

                1 Reply Last reply
                2
                • F Offline
                  F Offline
                  Fuchsiaff
                  wrote on last edited by
                  #8

                  Thank you so much! I got it to work!

                  1 Reply Last reply
                  1

                  • Login

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