Does qt gui thread start threads under the hood when calling methods from external objects?

I recently ran into a thread / memory issue when developing a Qt-based application in C ++, and I'm looking for the right explanation. I cannot post a fully functioning example, as this would require binding to Qt, etc. But the problem is quite clearly explained in a few short lines.

When I press the button on gui, something like this happens:

void MainWindow::onClick(){

    std::vector<int> vec;
    vec.push_back(0);

    dev.connect(vec);

    // do some more stuff
}

In this case, it devis a member MainWindowand has a class type Devicethat represents the hardware (or rather, the hardware drivers) with which I want to establish a connection. The code for connectsomething looks like this:

void Device::connect(const std::vector<int>& vec){
    // do some stuff with vec that takes a long time
}

, , , , vec. , connect, : vec . , shared_ptr s.

, dev.connect(vec) GUI, Qt . , Qt , onClick ( - , , ), vec Device::connect, . , shared_ptr .

, , ? - Qt- - ?

+4
2

, , , QI ui - , , , .

- . , , , - . , , .

-, , , , , , ( , ).

, QT, , , , , .

, shared_ptr " " , , ( , ); .

+1

UKMonkey, "". .

, , , . , , ( ) , . shard_ptr s, , . ( ) . non-shared_ptr ( , ) .

, . , , - "". Qt , . , , connect.

0

Source: https://habr.com/ru/post/1690064/


All Articles