sark9012
sark9012

Reputation: 5717

QT Application crashing with QStringList pointers

I have two QStringList pointer variables called oldFiles and oldDirectories. They will contain the same amount of items.

I want to loop through one of them and then display the oldFiles text on a QLabel and create a QTextEdit to accompany each one.

So if there were 3 enteries in the oldFiles QStringList, I want a label and textedit 3 times.

I have the following code:

QVBoxLayout *vbox = new QVBoxLayout;

for(int i=0; i<oldFiles->size(); ++i){
    QString labelText = oldFiles[i];
    QLabel *label = new QLabel();
    label->setText(labelText);
    vbox->addWidget(label);
    QTextEdit *text = new QTextEdit();
    vbox->addWidget(text);
}

ui->widget->setLayout(vbox);

Firstly, it's throwing an error on line QString labelText = oldFiles[i]; saying conversion from QStringList to QString isn't viable.

Also, this code is crashing the application, not sure what's wrong?

Thanks.

Upvotes: 0

Views: 325

Answers (1)

Lochemage
Lochemage

Reputation: 3974

oldFiles is a QStringList pointer, that means you need to dereference it first before you access the index:

QString labelText = (*oldFiles)[i];

I believe you can also do

QString labelText = oldFiles->at(i);

but don't quote me on that, my Qt is rusty.

Upvotes: 1

Related Questions