c++ - 尝试在树莓派上部署 qt5 应用程序时出现奇怪的错误

标签 c++ linux raspberry-pi qt5 raspbian

我有一个项目是在 Ubuntu 14.04 LTS 上制作的,但是后来,我想测试 Raspberry Pi 是否能够运行我的这个小程序。 然后我按照这个 link 上的说明进行操作在 Pi 上本地编译和构建 qt5。

我成功地安装了 qt5,我什至可以编译和运行位于 qt 示例中的“cube”程序。

之后,我编译并安装了项目所需的 qtmultimedia 子模块。

好的,一切看起来都不错。然后我在 Pi 上克隆了我的项目,运行 qmake,然后运行 ​​make。直到...我收到此错误消息:

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

事情是......在代码的这个特定区域,我没有从 int 到 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;
    }
(...)
}

这是 Channel 构造函数:

        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;
    }
(...)

}

这里是 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

那么……有什么想法吗?我不知道出了什么问题。我的代码在 ubuntu 和 Windows 上编译时没有出现此错误消息。

最佳答案

QString 的默认参数无效:

QString label = NULL

NULL 只是 0 的宏,因此您实际上是说 QString label = 0QString 没有定义从 int 创建 QString 的方法,这是您出错的原因 - 在大多数平台上我猜测 QString(const char *) 构造函数将通过从 0const char * 的隐式转换被调用。

看起来你的 pi 无法弄清楚如何隐式转换 0。将其更改为 QString label = ""QString label = QString() 或类似内容。

关于c++ - 尝试在树莓派上部署 qt5 应用程序时出现奇怪的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29951044/

相关文章:

C++ 二进制搜索无法正常工作 - 查找不在数组中的元素

c - 从内核写入用户空间的问题 - linux 设备驱动程序

python - urllib2 开启HTTPS

c - 如何在 main 函数中调用 int 函数?

java - GPS项目的Android应用程序

c++ - 事件和参数列表错误

c++ - 如何从/向 boost MSM 状态机交换数据

c++ - 使用类外部模板类中的 typedef 成员作为成员函数的返回类型

linux - 在另一个文件中查找一个文件的内容

c - 在循环中执行多个管道