问题“使用已删除的函数 async_client(const async_client&) =delete;” MQTT 发布者

问题描述 投票:0回答:1

我的异步客户端功能有问题。 在编译时,Qt 创建者控制台显示该函数已被删除。

moc_displaywindow.cpp: In static member function ‘static void DisplayWindow::qt_static_metacall(QObject*, QMetaObject::Call, int, void**)’:
moc_displaywindow.cpp:109:143: error: use of deleted function ‘Publisher::Publisher(const Publisher&)’
         case 0: _t->commande((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2])),(*reinterpret_cast< Publisher(*)>(_a[3]))); break;
                                                                                                                                               ^
In file included from displaywindow.h:8,
                 from moc_displaywindow.cpp:9:
minipub.h:68:7: note: ‘Publisher::Publisher(const Publisher&)’ is implicitly deleted because the default definition would be ill-formed:
 class Publisher
       ^~~~~~~~~
minipub.h:68:7: error: use of deleted function ‘mqtt::async_client::async_client(const mqtt::async_client&)’
In file included from minipub.h:11,
                 from displaywindow.h:8,
                 from moc_displaywindow.cpp:9:
/usr/local/include/mqtt/async_client.h:153:2: note: declared here
  async_client(const async_client&) =delete;
  ^~~~~~~~~~~~
In file included from moc_displaywindow.cpp:9:
displaywindow.h:26:10: note:   initializing argument 3 of ‘void DisplayWindow::commande(int, int, Publisher)’
     void commande(int number, int order, Publisher pub);
          ^~~~~~~~
moc_displaywindow.cpp:110:227: error: use of deleted function ‘Publisher::Publisher(const Publisher&)’
         case 1: _t->switchImages((*reinterpret_cast< QPixmap(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2])),(*reinterpret_cast< int(*)>(_a[3])),(*reinterpret_cast< Publisher(*)>(_a[4])),(*reinterpret_cast< QLabel*(*)>(_a[5]))); break;
                                                                                                                                                                                                                                   ^
In file included from moc_displaywindow.cpp:9:
displaywindow.h:27:10: note:   initializing argument 4 of ‘void DisplayWindow::switchImages(QPixmap, int, int, Publisher, QLabel*)’
     void switchImages(QPixmap display,int number, int order, Publisher pub, QLabel *label);
          ^~~~~~~~~~~~
make: *** [Makefile:512: moc_displaywindow.o] Error 1
16:04:52: Le processus "/usr/bin/make" s'est terminé avec le code 2.
Erreur lors de la compilation/déploiement du projet IHM_ASTREOS_REPL_ETH_SOL (kit : Desktop)
When executing step "Make"

我不明白为什么。我已经在另一个工作代码上使用了它。

一些研究表明这是一个构造函数错误。但我不知道该怎么办。

minipub.h :

class Publisher
{
public:
    Publisher(const std::string &server);
    ~Publisher(){}

    void publish(const std::string &topic, const void *payload, size_t size, int qos);

private:
    mqtt::async_client client;
};

minipub.cpp:

Publisher::Publisher(const string &server) : client(server, CLIENT_ID, PERSIST_DIR){
    callback cb; //This does not stay accessible in memory ?!
    client.set_callback(cb);
     string timeLWT = TimeCode();
    // verifying the presence of the key and certificates.
    std::ifstream tstore(TRUST_STORE);
    if (!tstore) {
        std::cerr << "The trust store file does not exist: " << TRUST_STORE << endl;
    }

    std::ifstream kstore(KEY_STORE);
    if (!kstore) {
        std::cerr << "The key store file does not exist: " << KEY_STORE << endl;
    }
    string LWTAndTime = ID_CARD + ";" + "LWT" + ";" + timeLWT + ";" + ID_CARD;
    auto sslopts = mqtt::ssl_options_builder()
                       .trust_store(TRUST_STORE)
                       .key_store(KEY_STORE)
                       .error_handler([](const std::string& msg) {
                           std::cerr << "SSL Error: " << msg << std::endl;
                       })
                       .finalize();
    auto willmsg = mqtt::message(LWT_TOPIC,LWTAndTime,QOS,false);
    auto connOpts = mqtt::connect_options_builder()
    .clean_session()
    .will(std::move(willmsg))
        .ssl(std::move(sslopts))
    .finalize();
    try {
        cout << "\nConnecting..." << endl;
        mqtt::token_ptr conntok = client.connect(connOpts);
        cout << "Waiting for the connection..." << endl;
        conntok->wait();
        cout << "  ...OK" << endl;
    }
    catch (const mqtt::exception& exc) {
        cerr << exc.what() << endl;
    }
}

我尝试从另一个正在运行(在另一台设备上)相同问题的程序复制过去。

c++ mqtt qt-creator paho
1个回答
-3
投票

我想我曾经遇到过这个问题。

sudo apt-get update
开始,然后以
sudo apt upgrade
跟进。 重新启动系统后,任何库兼容性问题都可能消失。

© www.soinside.com 2019 - 2024. All rights reserved.