Skip to content
  • 0 Votes
    12 Posts
    1k Views
    S

    It is somehow reasonable to use QSharedPointer here. Most of the time it is not a good idea to use raw pointers (in modern C++). Someone has to manage the memory. Most of the time it will just work in Qt because most of the time Qt objects have a parent which will handle deletion of children when destroyed. If those pointers only live because they are inside a container, the container should use a smart pointer (I'd prefer std::shared_ptr over QSharedPointer, but that's a different topic).

    There is an easy solution to the problem of connecting when using a shared pointer inside the map. connect() expects a raw pointer. For a smart pointer you get its raw pointer by calling get, i.e. objectsList[obj1].get(). This is the whole trick here.

    @Linhares said in [SOLVED] Signals and slots as parameters:

    addConnection("object1", "signal1", "object2", "slot1");

    This approach will not work immediately. Once you get your connect() to compile it will tell you at runtime that the signal and slot could not be found. Certainly, you have to use the old connect syntax. The string needs to include the argument types, like "signal1(int)" or "slot1()". Or has that changed at some point?

  • 0 Votes
    7 Posts
    867 Views
    S

    @J-Hilk Thank you, JonB and you were right. For me it actually makes more sense that e.g. at first you connect to the device and then you say "okay, if the signal "connected" is emitted then call the function x.y.". So after changing it, it works now. However, after getting all services and calling "service->discoverDetails" and then "service->characteristics" the characteristics List is empty.

    After connection is successfull:

    void Scanner::startServiceDiscovery(){ connect(controller, &QLowEnergyController::discoveryFinished, this, &Scanner::discoveryFinished); controller->discoverServices(); } void Scanner::discoveryFinished(){ qDebug() << "\nService Discovery finished. Following Services found:\n"; QList<QBluetoothUuid> serviceList = controller->services(); for(QBluetoothUuid &sl : serviceList){ qDebug() << controller->createServiceObject(sl)->serviceName() << "Uuid: " << sl; } uartService = controller->createServiceObject(adafruitServiceUuid); qDebug() <<"\nChose the following service: " << (*uartService).serviceName(); connect(uartService, &QLowEnergyService::stateChanged, this, &Scanner::printChars); qDebug() << uartService->state(); //here the state is QLowEnergyService::DiscoveryRequired uartService->discoverDetails(); } void Scanner::printChars(){ qDebug() << uartService->state(); // here the state is now QLowEnergyService::DiscoveringServices const QList<QLowEnergyCharacteristic> chars = uartService->characteristics(); qDebug()<< chars.size(); //however the list size is 0 for (const QLowEnergyCharacteristic &ch : chars) { qDebug() << &ch; } }

    btw: I know that there is an example for BLE Scanner. But for a project, I want to create an own desktop application which connnects to a peripheral and live plots the data which are received from the sensor with qcustomplot. So I need a QWidget Application because QCustomPlot is a widget...

  • 0 Votes
    15 Posts
    6k Views
    Petross404_Petros SP

    @mrjj It goes like this :

    Ctor connects a pushbutton click with QtDice::reload which in turn calls QtDice::image_update to animate the gif and after it's finished, show an image.

    I found out what the problem is. QtDice::image_update is called multiple times and therefore it tries to setFileName every time. So a check if fileName() is empty must be done each time before attempting to setFileName.

    void QtDice::image_update(int image_number) { //Make sure we don't constantly re-append a fileName! if(movie->fileName() == "" ) { movie->setFileName(":/images/rolling_infinite.gif"); //If it still is empty print error and exit. Not good at all //TODO wrap the setFileName in some Qt assert to throw an exception if (movie->fileName() == "") { qDebug() << "Error! Couldn't set a fileName to read for the animation"; QApplication::quit(); } } m_ui->label->setMovie(movie); ..... }

    I don't know exactly why this failed ( I mean I could change the fileName as many times as I like), but I checked and rechecked that with this if (movie->fileName() == "" ).... the animation works.

    That could also explain why some (but not all) times the animation played the very first time I push the button (ie called the function) and the second time it stopped. If someone thinks that other reasons come into play, please inform me, I am more than glad to learn.

    For any of you, that is curious what is the code and/or want to c&c, this is the QtDice and this is a screenshot

    Have a nice afternoon!

  • 0 Votes
    7 Posts
    16k Views
    kshegunovK

    @mistralegna

    Thanks, it's exactly the answer I was waiting for.

    I'm glad. :D

    Thank you a lot for your answers!

    You're welcome.