小编ger*_*rum的帖子

具有自定义类型的 Qt Signal

我想用 Qt 发送带有参数的信号。该参数应该是一个自定义的结构体。我已经用 Q_DECLARE_METATYPE 注册了它,但它不起作用,我收到一些奇怪的编译错误。

她是我的代码:

助手.h

#ifndef HELPER_H
#define HELPER_H

#include <QString>
#include <QMetaType>
struct result{
    QString info;
bool sugestion;
};
Q_DECLARE_METATYPE(result)

#endif // HELPER_H
Run Code Online (Sandbox Code Playgroud)

分析器.h

#ifndef ANALYSER_H
#define ANALYSER_H
#include "helper.h"
#include <QObject>

class analyser: public QObject
{
    Q_OBJECT
public:
    void test()
    {
        result ret;
        ret.info="Hallo";
        emit show(ret);
    }
signals:
    void show(result r);
};

#endif // ANALYSER_H
Run Code Online (Sandbox Code Playgroud)

qmlbackend.h

#ifndef QMLBACKEND_H
#define QMLBACKEND_H

#include <QObject>
#include "helper.h"
#include <QDebug>

class QmlBackend : public QObject
{
public slots:
    void hit(result …
Run Code Online (Sandbox Code Playgroud)

c++ qt qml

5
推荐指数
1
解决办法
3890
查看次数

部分模板实例化

如果我有这两个模板类:

template<int a, typename V>
class A {
};

template<template<int, typename> typename V>
class  B {
};
Run Code Online (Sandbox Code Playgroud)

我可以写类似的东西B<A> a;。我怎样才能为这两个类实现类似的目标:

template<int a, typename V>
class A {
};

template<template<typename> typename V>
class  B {
};
Run Code Online (Sandbox Code Playgroud)

我想声明一个这样的变量B<A<1>> a;,但它说 A 需要 2 个参数,这对于 A 的实例是正确的,但我只想创建一个参数数量较少的新模板。

我怎样才能做到这一点?

c++ templates c++17

4
推荐指数
1
解决办法
58
查看次数

递归飞船操作符

我已经编写了这个简单的代码,但它无法编译,因为比较被隐式删除了。

struct Tree {
    std::vector<Tree> child;

    friend auto operator<=>(const Tree &a, const Tree &b) = default;
}
int main(){
    Tree t;
    std::cout<<(t<t)<<std::endl;
}
Run Code Online (Sandbox Code Playgroud)

任何人都可以向我解释如何解决问题或至少为什么它不起作用?

编辑:用“g++ -std=gnu++2a main.cpp”编译 Edit2:这是输出的错误部分(后面是很多很多的候选行):

main.cpp: In function 'int main()':
main.cpp:31:25: error: use of deleted function 'constexpr auto operator<=>(const Tree&, const Tree&)'
   31 |     std::cout << (tmp < tmp) << std::endl;
      |                         ^~~
main.cpp:12:17: note: 'constexpr auto operator<=>(const Tree&, const Tree&)' is implicitly deleted because the default definition would be ill-formed:
   12 |     friend auto operator<=>(const Tree …
Run Code Online (Sandbox Code Playgroud)

c++ spaceship-operator c++20

2
推荐指数
1
解决办法
92
查看次数

标签 统计

c++ ×3

c++17 ×1

c++20 ×1

qml ×1

qt ×1

spaceship-operator ×1

templates ×1