Please nominate your Qt Champions for 2021!

QVector: no match for 'operator+'

  • I am passing a QVector from one window to another, I want to append the value present in QVector from previous window to a QString in present window. I get the error when I perform the addition @no match for 'operator+'@

    Here is my code:


    @void SelectOS::processNextButton()
    QString path;
    path = qApp->applicationDirPath()+"/WIN/32Bit";
    SelectSoftware *ss = new SelectSoftware();

    QVector<QString> SelectOS::getosName(){
    so = new SelectOS();
    return so->osName;


    @void SelectSoftware::getSoftwareDetails()

    SelectOS *so = new SelectOS();
    SelectSoftware *ss = new SelectSoftware();
    ss->os = so->getosName();
    QString fileName = ss->os + "/" +SOFTWARELIST; // Here I get the error...
    QFile file&#40;fileName&#41;;
    if (! | QIODevice::Text)){
        QString msg = "Could not find the file " + fileName;
    QTextStream in(&file);
    while (!in.atEnd()) {
        QString line = in.readLine();


  • If SOFTWARELIST is defined as a C-style string, you can just leave out the plus sign, and the compiler will concatenate them:

    QString fileName = ss->os + "/" SOFTWARELIST;

  • Moderators

    according to the docs QVector only has the operator+ defined for other vectors and not for it's types it is holding.

    There are 3 possibilities for you now ;)

    1. use the operator<<
    2. use the append-Method of QVector
    3. or write your own operator+

    Something like this (not tested):

    QVector<T> & operator+ (QVector<T> &vector, const T &value)
    return (vector << value);

  • If you want to add to QVector use qppend() or if your intention is to to add to a vector operator[] with appropriate index.
    In your case,
    ss->os[0] + "/" +SOFTWARELIST;

    By the way, why are you returning a vector?? If its simple QString You could very well use a QStringList.

  • I want to pass list of String variables from one Window to another, which one i need to use? QList type or QString or QVector?

    For example, SOFTWARELIST is a simple .txt file, the list of directories will be iterated from that list and will be displayed, each directory having checkbox[i] and combobox[i]. I need to send this list to new window.. How can I do this??

  • QStringList objListofDirs;
    while you have not reached the end of file {
    Get a file line in var QString strLine;
    objListofDirs<<strLine; // This will append to QStringList


    So return QStringList or a reference to it from your function which will be input to the other window function which can then iterate the list and give you values

    Iteration should be
    for (int i = 0; i < objListofDirs.size(); ++i) {
    //Do whatever with the directory

  • Well, in the other WIndow, the constructor must be of QStringList type, is it? Or I can pass to any Constructor? Actually in my application, there are total of 8 Windows, except first window, each and every window has Back and Next actions, and I am calling new Class of Each window when moving backward and forward, if the argument is missing or empty, the application is crashing...

  • You have a list of strings that you can use any way.
    If it suits your application logic pass a const QStringList reference in the constructor and access the data by iteration to either suitably store in your data structure or as is.
    Since your application crashes you need to put memory guards / checks before accessing any memory

Log in to reply