qtdefinitionqstringlist

Define static QStringList directly


I want to create and define a static QStringList in an external file. With gcc ist is possible to do it like this:

static QStringList list1 = {item1, item2, item4, ...};

But with the visualStudio c++ compiler it is not possible to do it this way. I get the error:

initializer-list can not be convertedinto QStringList

For me it is important, that I can define the list directly after the declaration.

Because I dont want to define it in the main file.

For example:

main.cpp:

#include "stringlist.cpp"    
int main()
{
    QList<QStringList> list;
    list << list1;
}
...

stringlist.cpp:

#include <QStringList>
static QStringList list1 = {"hi", "hello"};

I want to do that because the definition of the QStringList is very long and it is very confusing if such a big definition is somewhere between the other code.


Solution

  • I found a way to solve the Problem:

    You have to type the following snippet into your .pro file.

    DEFINES += Q_COMPILER_INITIALIZER_LISTS