PDA

View Full Version : listWidget select item, return index?



noborder
7th January 2013, 13:13
Need right way to recieve item index when changed to another item

need use currentRowChanged ? How?

i have


void View::unzipdone(QString namepath)
{
QDir dir(namepath);
uint i = 1;
QStringList filters;

filters << "*.jpg" << "*.png" << "*.bmp";
dir.setNameFilters(filters);

foreach (QFileInfo mitm, dir.entryInfoList())
{
ui->listWidget->addItem("picture "+QString::number(i));
i++;
}
}

Santosh Reddy
7th January 2013, 13:54
Could you reword the question?

From where you want to send item (emit signal) view/model/item?
To where you want to receive item index (slotl) view/model/item?

noborder
7th January 2013, 17:43
when activate item in listWidget (via mouse click, or keyboard) emit signal with item index.

i do


void View::unzipdone(QString namepath)
{
QDir dir(namepath);
uint i = 1;
QStringList filters;

filters << "*.jpg" << "*.png" << "*.bmp";
dir.setNameFilters(filters);

foreach (QFileInfo mitm, dir.entryInfoList())
{
ui->listWidget->addItem("picture "+QString::number(i));
i++;
}
connect(ui->listWidget, SIGNAL(currentRowChanged(int)), &m_imageviewer, SLOT(picindex(int))); //error
}

recieve error : no matching function for call to 'ComicView::connect(QListWidget*&, const char*, ImageViewer*, const char*)'
????

Zlatomir
7th January 2013, 18:50
try:
QObject::connect(ui->listWidget, SIGNAL(currentRowChanged(int)), &m_imageviewer, SLOT(picindex(int)));
i'm not sure that will help, you have some modifications (at least ComicView from error and View:: in code) after you got the error you told us, so if that won't help post the updated code and error message.

Also are you sure that you want to connect when unzipdone (instead of for example in the ComicView constructor)?
And make sure that m_imageviewer stays alive as long as you need it to receive the changes to selection.

noborder
7th January 2013, 18:55
Found error

m_imageviewer isn`t inherited from QObject

thx