I
I
Ilnur2018-02-25 16:43:22
Qt
Ilnur, 2018-02-25 16:43:22

Why doesn't foreach work in C++ Qt?

Hello everyone)
There is a ready class QSerialDevice
There is an example Enumerator (a list of available COM ports)

foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) {
        QString s = QObject::tr("Port: ") + info.portName() + "\n"
                    + QObject::tr("Location: ") + info.systemLocation() + "\n"
                    + QObject::tr("Description: ") + info.description() + "\n"
                    + QObject::tr("Manufacturer: ") + info.manufacturer() + "\n"
                    + QObject::tr("Serial number: ") + info.serialNumber() + "\n"
                    + QObject::tr("Vendor Identifier: ") + (info.hasVendorIdentifier() ? QString::number(info.vendorIdentifier(), 16) : QString()) + "\n"
                    + QObject::tr("Product Identifier: ") + (info.hasProductIdentifier() ? QString::number(info.productIdentifier(), 16) : QString()) + "\n"
                    + QObject::tr("Busy: ") + (info.isBusy() ? QObject::tr("Yes") : QObject::tr("No")) + "\n";


    }

I transfer this part of the program code to my program and get the following errors:
1. expected primary-expression before 'const'
2. 'foreach' was not declared in this
scope support foreach)
What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav Makarov, 2018-02-25
@Il_noor

Why do you need this foreach, use a plus range-for .

A
Andrei Vukolov, 2018-02-28
@twdragon

CONFIG += c++14
to a .pro file for qmake. This will include all chips of the 14th standard. By default, you may well have the C ++ 97 standard.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question