开发者

QVector not appending!

I am having a problem.

For some reason, despite the fact I have a value in a QString, doing an append() to a QVector isn't working, and I end up still having just an empty vector.

    QList<QVariant> listServers = mapRepos.values ( "servers" ); // Finally, the last data structure, for holding server lists.
    // Populate the repository information with the server lists.

    for ( int i = 0; i < listServers.size(); ++i ) {
      for ( int j = 0; j < listServers.at ( i ).toList().size(); ++j ) {
        std::cout << "On file: " << listServers.at ( i ).toList().at ( j ).toString().toStdString() << std::endl;
        std::cout << "Type #: " << listServers.at ( i ).toList().at ( j ).type() << std::endl;
        buffer3 = listServers.at ( i ).toList().at ( j ).toString();
        std::cout << "In buffer: (" << buffer3.toStdString() << ")" << std::endl;
        arrayRepos.value ( j ).urls.append ( buffer3 );
        std::cout << "In memory: " << arrayRepos.value ( i ).urls.value ( i ).toStdString() << std::endl;
      }
    }
  }

This is the relevant snippet in the source file. The first cout returns a URL, the second URL returns 10 (Which according to the documentations means the QVariant contains a string, which is correct. The third cout outputs the string correctly. Then, the last one outputs no string. Note the presence of the append line there. All my programming common sense tells me that vector should be populated now, but taking a peek at its size shows a size of 0, meaning that QString isn't put in.

The urls QVector is part of a struct:

struct repo {

QString name; // Name 开发者_JAVA技巧of the repository.

QVector<QString> urls; // Address of server or list of mirrors.

};

QString name is part of an earlier bit of code that works okay and is not relevant to this problem.

I can't think of any reason why append() or push_back() wouldn't work.


What is the type of arrayRepos, I guess it is some kind of Qt container (QVector, QList, etc). In this case arrayRepos.value (j) return a copy of a repo structure when you need a reference, thus you need to use either operator[] or at(j) member function.


Can you break up this arrayRepos.value ( j ).urls.append ( buffer3 ); code to individual statements and then try.

Like:

QVector<QString> tmpurls = arrayRepos.value ( j ).urls;
tmpurls.append ( buffer3 );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜