Skip to content
Advertisement

Strange error while trying to deploy qt5 app on raspberry pi

I have a project which I’ve made on Ubuntu 14.04 LTS, but then, I wanted to test if the Raspberry Pi was capable of running this little program of mine. Then I’ve followed the instructions on this link to compile and build qt5 natively on the Pi.

I’ve managed to install qt5 without problems, I could even compile and run the “cube” program that is located on the qt samples.

After that, I’ve compiled and installed the qtmultimedia submodule, which I needed for my project.

Ok, things were looking good. Then I cloned my project on the Pi, ran qmake, and after that I ran make. Until… I got this error message:

In file included from ../mainWindow.h:14:0,
             from ../main.cpp:3:
../core/core.h: In constructor ‘bumbatv::core::Core::Core()’:
../core/core.h:37:36: error: conversion from ‘int’ to ‘QString’ is ambiguous
../core/core.h:37:36: note: candidates are:
/usr/local/qt5/include/QtCore/qstring.h:649:31: note: QString::QString(const char*)
/usr/local/qt5/include/QtCore/qstring.h:214:14: note: QString::QString(const QChar*, int)
Makefile:2564: recipe for target 'main.o' failed
make: *** [main.o] Error 1

Thing is… In this particular area of the code, I have no conversion from int to QString!

class Core : public QObject
{
Q_OBJECT
private:
    static Core *instance_;
    QHash <int, Channel*> channels_;
    int currentChannelId_;
    QString computerName_;
    QString projectDirectory_; 
    Definitions::kPlayerStatus player_;
    QHash<int, Media*> medias_;
    QString userEmail_;
    QString userPassword_;
    QString userPasswordEncrypted_;
    bool logged_;

    Core(){
        Channel *channel = new Channel; // This is the error line.
        channels_.insert(channel->getId(),channel);
        currentChannelId_ = channel->getId();
        player_ = Definitions::kStopped;
        logged_ = false;
    }

    Core(const Core&);
    Core& operator=(const Core&);
    /* Protect destructor.
     * Deletes all elements allocated in the Document.
     */
    ~Core()
    {
        // Delete channels
        foreach (Channel *c, channels_)
            delete c;
    }
(...)
}

And here’s the Channel constructor:

        class Channel : public QObject
{
Q_OBJECT
private:

    static int countChannel_; 
    int idChannel_; 
    QString label_; 
    int currentMediaId_; 
    int totalTime_; 
    int order_; 

    QHash<int, Media*> medias_;  


signals:
    (...)

public:
    Channel(int id = -1, int order = -1, int totalTime = -1, QString label = NULL) {
        if(id==-1){
            idChannel_ = countChannel_++;
        }else{
            idChannel_ = id;
            countChannel_ = countChannel_ <= id ? id+1 : countChannel_;
        }

        order_ = order == -1 ? idChannel_ : order;
        totalTime_ = totalTime == -1 ? 0 : totalTime;
        label_ = label == NULL ? QString("Channel %1").arg(idChannel_+1) : label;
    }

    /* Protect destructor.
     * Deletes all elements allocated in the Channel.
     */
    ~Channel()
    {
        // Delete medias
        foreach (Media *m, medias_)
            delete m;
    }
(...)

}

And here is the command called by make:

/usr/bin/g++ -c -pipe -marm -mfpu=vfp -mtune=arm1176jzf-s -march=armv6zk -mabi=aapcs-linux -mfloat-abi=hard -O2 -std=c++0x -Wall -W -D_REENTRANT -fPIE -DQT_NO_SSL -DQT_NO_DEBUG -DQT_MULTIMEDIAWIDGETS_LIB -DQT_MULTIMEDIA_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_XML_LIB -DQT_CORE_LIB -I../../vodas_desktop -I. -I/usr/local/qt5/include -I/usr/local/qt5/include/QtMultimediaWidgets -I/usr/local/qt5/include/QtMultimedia -I/usr/local/qt5/include/QtWidgets -I/usr/local/qt5/include/QtGui -I/usr/local/qt5/include/QtNetwork -I/usr/local/qt5/include/QtXml -I/usr/local/qt5/include/QtCore -I. -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux -I/usr/local/qt5/mkspecs/devices/linux-rasp-pi-g++ -o main.o ../main.cpp

So… Any thoughts? I have no idea of what is wrong. My code compiles on ubuntu and on Windows without this error message.

Advertisement

Answer

Your default argument for QString isn’t valid:

QString label = NULL

NULL is just a macro for 0, so you are effectively saying QString label = 0. QString doesn’t define a way to create a QString from an int, which is the reason for your error – on most platforms I’m guessing the QString(const char *) constructor would get called with an implicit conversion from 0 to const char *.

It looks like your pi had trouble figuring out how to implicitly convert that 0. Change it to QString label = "", QString label = QString(), or something similar.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement