Qt隐式实例化未定义的模板'QList<VPNConnection>'。

9

看到这个问题后,我查看了一些Stack Overflow的问题,其中有一半似乎不适用,而另一半,说实话,我就是不理解。

问题:

这是我的问题的简单实现,

ERROR:未定义模板“QList<code><VPNConnection></code>”的隐式实例化'

具体地,在结构体中的 VPNList 对象被上述错误下划线标记。

值得注意的是,在一个帖子中提到,应该将您的“子项”放在父项之上,否则将实现一种原型类型,因此VPNConnection位于User_VPN_Info之上。

基本说明:

结构体User_VPN_Info应以QList的形式实现结构体VPNConnection,以容纳多个VPNConnection

代码:

struct VPNConnection{
    QString ip,cipher,protocol;
    int port;
    bool lzo_compression;

    VPNConnection(){}

    VPNConnection(QString _ip, QString _cipher, QString _protocol, int _port, bool _comp){
        ip = _ip;
        cipher = _cipher;
        protocol = _protocol;
        port = _port;
        lzo_compression = _comp;
    }
};

struct User_VPN_Info{
    QString vpn_name, vpn_expire;
    int DaysLeft;
    QList<VPNConnection> VPNList;
                         --------              <<< --- underlined with error   
    User_VPN_Info(){}

    User_VPN_Info(QString _vpn_name, QString _vpn_expire, int _DaysLeft){
        vpn_name = _vpn_name;
        vpn_expire = _vpn_expire;
        DaysLeft = _DaysLeft;
    }

    QString getString(){
        return(vpn_name + " + " + vpn_expire + " + " + QString::number(DaysLeft) + " ; ");
    }
};

我想了解是什么原因导致此错误并为何会在这里发生?

ERROR:未定义模板“QList<VPNConnection>”的隐式实例化

更新 在进行更多研究后,我遇到了这个问题

用户-dasblinkenlight

将其应用为指针

因此更改为:
QList<VPNConnection> *VPNList;

已解决此问题。

有人愿意提供解释吗?

1个回答

17

那是因为您没有包含QList头文件,所以您缺少QList的定义,在您使用该类型的变量时需要这个定义。

QList<VPNConnection> VPNList;

然而,看起来你包含了一些头文件(例如QString),使得QList可用。否则,你将会收到一个错误:

未知类型名称 QList

这就解释了为什么使用指针的解决方案可以正常工作,因为它只需要对QList进行前向声明即可。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接