-2

I have a problem with the async-client function. At compiled time the Qt creator console says that the function has been deleted.

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"

I don't understand why. I have used it on another code with work.

Some research indicates that it's a constructor error. But i don't know what to do.

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;
    }
}

I tried copy past from another program that is working (on another device) same problem.

ok2c
  • 26,450
  • 5
  • 63
  • 71
Flowmikos
  • 1
  • 2
  • `mqtt::async_client` is not a function but a class, and its instances can't be copied. – molbdnilo Aug 24 '23 at 14:10
  • If you read the error you will see it is complaining about `DisplayWindow::commande` and `DisplayWindow::switchImages`, who should be taking `Publisher` by reference, not by copy. – Botje Aug 24 '23 at 14:12
  • @molbdnilo I used this class declaration from the example. What shoud i do to make it work ? – Flowmikos Aug 24 '23 at 14:50
  • @Botje what do you mean by reference not by copy ? – Flowmikos Aug 24 '23 at 14:51
  • If you don't know what references are, even though you are using them, it's time to get a [good book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) and start at the beginning. – molbdnilo Aug 24 '23 at 15:30
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Aug 25 '23 at 07:56

1 Answers1

-3

I think I've had this problem once.

Start with sudo apt-get update, and follow up with sudo apt upgrade. End with a reboot of your system, and any library compatibility issue may disappear.

  • Tried and do not work. – Flowmikos Aug 24 '23 at 14:52
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 25 '23 at 07:06