I have this code

demo.h private: QLineEdit *serialNumberText; main.cpp //СОЗДАЕТСЯ КНОПКА QHBoxLayout *serial = new QHBoxLayout(); serial->addWidget(new QLabel("S/N:")); serial->addWidget(serialNumberText); serial->addWidget(serialNumberBtn); //САМА ФУНКЦИЯ void Main::serialNumberFunc(){ std::cout << serialNumberText->text().toStdString() << std::endl; } 

After clicking on the button, the program simply closes. The debugger shows a Segmentation fault, on the string std::cout << serialNumberText->text().toStdString() << std::endl;

  • one
    Is your serialNumberText initialized at all? - free_ze
  • @free_ze well is it displayed on screen or what do you mean? - Insider
  • one
    Where is your memory allocation (initialization) serialNumberText ? - ixSci
  • If the debugger has already indicated a line to you, try to divide this line into several actions, or otherwise modify it. With these actions you can even more localize the problem, and as a result - find a solution faster. - αλεχολυτ
  • Most likely, you use the form created in the designer. And the QLineEdit *serialNumberText not initialized with the correct value. - aleks.andr

1 answer 1

I solved the problem by creating forms in the designer and getting the values ​​I needed through

 QString string = ui.lineEdit->text(); serialNumberPDF = string.toInt(); 

lineEdit in this case is a former serialNumberText

  • and now add to the output of the text method .toLatin1 (). data (); and it will not be necessary to place it in QString. Here your question was considered by forum.qt.io/topic/39486/… - perfect