I just can not understand. I created a class with a QVector inside that accepts another class, and a method with which you can add this class to it. And here is the problem: Every time I use this method, I’m thrown out, as if the program is not responding. Debagger says that it is SIGSEGV and sends me to this line

void QVector<T>::append(const T &t) { const bool isTooSmall = uint(d->size + 1) > d->alloc; //Вот эта строчка 

...

  • Can you see the code that uses the vector? - yrHeTaTeJlb
  • I think there elements are added in an infinite (or rather infinite) cycle. And they really added a lot. - KoVadim
  • @yrHeTaTeJlb void Worker :: add_Ressource (Ressource & l) {ressource.push_back (l); } - Astemir Tsechoev
  • And what should you do, @KoVadim? - Astemir Tsechoev
  • @AstemirTsechoev, I think KoVadim hints that memory is running out. Can I see all the code? Well, or a minimal example that reproduces the error? - yrHeTaTeJlb

1 answer 1

Errors of work with memory are shown not where the error was made in the code. Therefore, it is not necessary that once the debugger sent you to this line, the error is in it. In addition, this is not your code, but the Qt library code, and all libraries must be considered sinless until proven otherwise. And you can add elements of any class to the vector as follows.

 class SomeClass : public QObject { explicit SomeClass(QObject *parent = nullptr); } ... QVector<SomeClass> vector; SomeClass a, b, c; vector.append(a); vector.append(b); vector.append(c); 
  • I tried to make the vector public, the same problem was revealed. Used append, but all in vain. In dialog.cpp (this is the main window). I have a class object that I pass through the parameters of the method of another object of another class so that it accommodates all the data in a vector. - Astemir Tsechoev
  • I worked through push_back and everything worked well - Vyacheslav Savchenko
  • @AstemirTsechoev, publicity does not affect memory errors. Memory errors are related to the fact that you are trying to access a class object that you have deleted or have not yet created. The code you give has nothing to do with the problem. - maestro