Reputation: 81
I am having some .jpg images in a folder which need to be displayed in QtListWidget. I am able to display the list of items in a particular folder in QtListWidget, but unable to open the item when i click it. I learned in tutorial one should use "connect" for doing it, i tried it but error is happening. My code in .cpp file is as follows. Any help is most welcomed...
QDir myPath("/home/mit/Desktop/Ui_dev_mits_cars/visual_image");
myPath.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
myList = myPath.entryList();
ui->listWidget1->addItems(myList);
Upvotes: 1
Views: 486
Reputation: 53235
Right, so the issue is at least two-folded with your code:
connect(MyList,SIGNAL(doubleClicked(QListWidgetItem *)),this,SLOT(test(QListWidgetItem *)));
First of all, you are trying to use a QStringList
value based object rather than pointer. Also, you should use the pointer pointing to the QListWidget
instance.
Secondly, you are using the signal wrong. It is parameter is a QModelIndex
as opposed to a QListWidgetItem
. See the documentation for details:
void QAbstractItemView::doubleClicked(const QModelIndex & index) [signal]
This signal is emitted when a mouse button is double-clicked. The item the mouse was double-clicked on is specified by index. The signal is only emitted when the index is valid.
So, grab the model index and in your slot, get the data out of that model index either by using the internal pointer, or preferrably the data()
method.
Upvotes: 1