I know, the question is Nubian, but all the same. I didn't work with Qt.

Some operations are QTextStream with QTextStream .

Then I try to delete it through delete and the compiler gives an error. I look at methods and do not find anything similar to methods close , Dispose (this is already from C #).

So how to remove instances of similar objects? There is no wish to catch a memory leak.

Error text:

error: C2440: delete: unable to convert "QTextStream" to "void *" There is no user-defined conversion operator available or the operator cannot be called to perform this conversion

 QTextStream qtin(stdin); QString input = qtin.readLine(); delete qtin; 
  • Error text we will guess the whole stack? - gbg
  • It is not necessary to be such an ulcer, I thought this is a fairly common problem for Qt newbies. Anyway, the error text is added - user64675
  • now show the code you wrote. By the third five-year period, at such a pace we will formulate a question that can be answered without shamanistic methods. - gbg
  • It is very difficult to answer your question, because you are doing something very strange - you are trying to turn an instance created on the stack (which follows from the text of the error) into a pointer, and then delete. - gbg
  • 2
    Well, maybe not on the stack, maybe in the data segment, it is impossible to make exact conclusions from the code fragment. But the fact is that you did not create this instance of an object with the help of new , and therefore it cannot be deleted with the help of delete . - PinkTux

1 answer 1

A QString instance is created on the stack and is local. It will be removed automatically when it disappears from view.

I remind you that the scope of the variable is the block {} in which it is declared. The exception is global variables, that is, variables declared outside the text of functions. However, the quality design of the application directly prohibits any global variables.

Your third line is delete qtin; just not needed.

About your statement "there is no stack." There is a stack. The stack here refers to the memory area of ​​the application where all local variables fall. It is organized as a stack, and with hardware support, at the level of the processor instructions.

  • 2
    > Exception - global variables And static class fields and static variables inside functions) - free_ze