QTreeView and its signals, and setting directory of its QFileSystemModel
Still working on a desktop photo calendar, and the QTreeView that will be used to select photos is baffling me. I've connected both the activated and clicked signals to a slot, but nothing I do can get it triggered. The connection (also tested replacing clicked with activated):
@connect(ui->browserTreeView, SIGNAL(clicked(QModelIndex)), this, SLOT(photoSelectionChanged(QModelIndex)));
Direct link to the connect and the slot:
Also, what is the best way to set its current directory? If I do this:
That seems to set a hard path; I can not navigate above that directory, or see any files in it.
Thanks for any help!!!
Did you check if you get any error about signals and slots in the application output panel ? If not, are you sure you are printing something that currently contains something ?
IIRC, you need to call setRootPath on your QFileSystemModel
Hope it helps
Well the setRootPath helped it be more navigable, but did not make the signals work.
Just to be sure, I addd a qDebug("hello world") above the line printing the index value. Still I see nothing.
Did you check if you had any warnings on the console ?
Yes - there were no warnings at all on the console.
Does your QTreeWidget get populated correctly ?
Seems to be. I can definitely navigate the filesystem with it.
I am starting to wonder if only the Enter key can send these signals on Linux, and in my case Enter is closing the dialog. That wouldn't make much sense with clicked() though.
Ultimately I want a signal to fire when a user clicks or moves the highlight through the tree with the arrow keys.
Then it should be the activated signal IIRC
Yeah, that's what I thought too, and it's the first one I tried; it's just not getting fired!
I guess I should try to come up with a minimal example and see if it works there.
In between, what version of Qt and what OS are you using ?
qt 5.3.1 on Arch Linux, from the Arch repos....
Guess I'll eat my words here. In the slot I added this:
@ QMessageBox::information(this, "test", "hello we reached the slot!");
and changed the signal to activated(), and it did show this when I clicked on an entry! (But not on moving the selection with the arrow keys.)
But that leaves the perplexing question of why these did not output anything.
@ qDebug("hello world\n");
I've used qDebug before in this project ...
Add some defines somewhere in your pro file ?
Changed Qt version ? Release VS Debug ?