QList<QPixmap> ‘index out of range’
I’m trying to make a list of pixmaps for a program I’m writing, but when I try to get something from the list, I get this error:
ASSERT failure in QList<T>::at: “index out of range”, file ..\..\..\..\QtSDK\Desktop\Qt\4.7.3\mingw\include/QtCore/qlist.h, line 456
Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.
When I went into Qt Creator’s debug mode, I found that the list of pixmaps wasn’t being populated at all. I think I need to create a new QList<Pixmap> in the MainWindow constructor (with ‘thumbnailPixmapList = new QList<QPixmap>();’), but the compiler gives me this error:
error: no match for ‘operator=’ in ‘((MainWindow*)this)->MainWindow::thumbnailPixmapList = (operator new(4u), (<statement>, ((QList<QPixmap>*)<anonymous>)))’
This is the function I’m using to populate the list:
- void MainWindow::createThumbnailPixmaps()
- {
- for (int i=0; i<thumbnailPixmapList.size(); ++i)
- {
- thumbnailPixmapList.insert(i, thumbnailPix);
- }
- }
This is one of the functions I want to use to get a list item:
- void MainWindow::forwardSlice()
- {
- s+=1;
- ui->horizontalSlider->setValue(s);
- newSlice2->setPixmap(nextPix);
- ui->sliceView->update();
- }
Please let me know if there’s anything I’m doing wrong.
7 replies
I do not know where you are getting the parts of your picture, but all looks a little suspicious to me.
Assuming that somehow extractSlice (0, j) makes sense for j up to 9. This would make more sense.
- void MainWindow::createThumbnailPixmaps()
- {
- for (int j=0; j < 10; ++j)
- {
- thumbnailPixmapList.push_back (thumbnailPix);
- }
- }
For reading you could use something similar to:
- void MainWindow::forwardSlice()
- {
- if ( s >= 0 && s < thumbnailPixmapList.size() )
- {
- ++s;
- ui->horizontalSlider->setValue(s);
- newSlice2->setPixmap(nextPix);
- ui->sliceView->update();
- }
- }
Disclaimer: This part of code is typed directly into the thread. Furthermore, I cannot know what you are up to. So, the snippet might need significant additions until it runs as you need.
You must log in to post a reply. Not a member yet? Register here!




