Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QT cross compilation error for raspberry pi - QStringList and QFile members missing



  • Hi,
    I am working with QT for cross compiling the application for raspberry pi.
    I want to create a CSV file and save the data for further analysis.

    Below is the sample code :

    #include <QList>
    #include <QColor>
    #include <QString>
    #include <QStringList>
    #include <QFile>
    #include <QTextStream>
    #include <QDebug>
    
    QList<QRgb> GetPixels()
    {
        QList<QRgb> pixels;
        pixels << qRgb(11, 255, 0) << qRgb(167, 209, 89) << qRgb(34, 55, 12);
    
        return pixels;
    }
    
    QList<QStringList> PixelsToStrings(const QList<QRgb>& pixels)
    {
        QList<QStringList> strings;
        for (int i = 0; i < pixels.size(); ++i)
        {
            QStringList values;
            values << QString::number(qRed(pixels.at(i))) <<
                      QString::number(qGreen(pixels.at(i))) <<
                      QString::number(qBlue(pixels.at(i)));
    
            strings << values;
        }
    
        return strings;
    
    }
    
    void WriteToCSV(const QList<QStringList>& pixels)
    {
        // Open csv-file
        QFile file("pixels.csv");
        file.open(QIODevice::Append | QIODevice::Text);
    
        // Write data to file
        QTextStream stream(&file);
        QString separator(",");
        for (int i = 0; i < pixels.size(); ++i)
        {
            stream << pixels.at(i).join(separator) << endl;
        }
    
        stream.flush();
        file.close();
    }
    
    QList<QStringList> ReadCSV()
    {
        // Open csv-file
        QFile file("pixels.csv");
        file.open(QIODevice::ReadOnly | QIODevice::Text);
    
        // Read data from file
        QTextStream stream(&file);
        QList<QStringList> data;
        QString separator(",");
        while (stream.atEnd() == false)
        {
            QString line = stream.readLine();
            data << line.split(separator);
        }
    
        file.close();
        return data;
    }
    
    void Print(const QList<QStringList>& data)
    {
        for (int i = 0; i < data.size(); ++i)
        {
            qDebug() << data.at(i).join(", ");
        }
    }
    
    int main()
    {
        QList<QRgb> pixels = GetPixels();
        QList<QStringList> pixelsStr = PixelsToStrings(pixels);
        WriteToCSV(pixelsStr);
    
        QList<QStringList> readData = ReadCSV();
        Print(readData);
    
        return 0;
    }
    

    This code is working fine on native compiler - Linux (ubuntu) but when cross compiling for raspberry pi, Errors facing -

    1. .Join member is missing in QStringList , there are other members like isEmpty etc also missing.
    2. .open - No matching member function for call to 'open'.

    If anyone faced similar issues and knows the solution, please share with me. It would be really appreciated.

    Similar post I found - https://forum.qt.io/topic/118482/qstringlist-missing-methods



  • @RiyG22 said in QT cross compilation error for raspberry pi - QStringList and QFile members missing:

    when cross compiling for raspberry pi

    How did you install / setup RPi cross-compiling tools?



  • @KroMignon , Thank you for your quick reply.
    I followed these below links and created a kit successfully -
    https://www.ics.com/blog/configuring-qt-creator-raspberry-pi
    https://wiki.qt.io/RaspberryPi2EGLFS



  • @RiyG22 Which one did you use? Which Qt Version did you build?
    Have you try to build your project on RPi himself?



  • @KroMignon ,
    Used One- https://wiki.qt.io/RaspberryPi2EGLFS
    Qt version - Qt 5.13.1
    No, I've not tried to build the project on RPI itself. I 've cross compiling the project without adding CSV file functionality and successfully run it on RPi.



  • Solved the issue with disabling Clang code model.



  • @RiyG22
    I don't know whether it also applies to your situation, but as of Ubuntu 20.04 you now have to additionally apt-get a clang8 package --- I forget the exact name, but you can Google --- to make clang work correctly.


Log in to reply