QTreeView::doubleClicked not sending a signal
-
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.
-
Hi,
Are you sure that
dir->viewis not a dangling pointer ? Because, for example, you shadowed it in your class constructor. -
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 -
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@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 ?
-
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?
-
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?
@Fuchsiaff
Hi
kinda yes, you make a Directory object in mainwin and hook up its signal, but the one
fromclass 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.