[img]https:/ /i.stack.imgur.com/ata41.png[/img]
Три поля ввода созданы с помощью QLineEdit и подключены к функции onTextEdited:< /p>
Код: Выделить всё
QWidget * fieldWindow = new QWidget;
QHBoxLayout *layout = new QHBoxLayout(fieldWindow);
fieldWindow->setStyleSheet(widgetSS);
_lineEditX = new QLineEdit();
_lineEditY = new QLineEdit();
_lineEditZ = new QLineEdit();
connect(_lineEditX, &QLineEdit::textChanged, this, &NodeVec3::onTextEdited);
connect(_lineEditY, &QLineEdit::textChanged, this, &NodeVec3::onTextEdited);
connect(_lineEditZ, &QLineEdit::textChanged, this, &NodeVec3::onTextEdited);
layout->addWidget(_lineEditX);
layout->addWidget(_lineEditY);
layout->addWidget(_lineEditZ);
Код: Выделить всё
void NodeVec3::onTextEdited(QString const &str)
{
bool ok = false;
double number = str.toDouble(&ok); // This works
// Written this way so the vector is read and updated every time a change is made
// ^ so I supposed.
double numberX = _lineEditX->text().toDouble(); // This does not work
double numberY = _lineEditY->text().toDouble();
double numberZ = _lineEditZ->text().toDouble();
if (ok) {
// ...
} else {
// ...
}
}
Код: Выделить всё
str.toDouble(&ok)
Поэтому я решил для чтения из всех трех полей QLineEdit после этого, логика заключается в том, что QLineEdit должен иметь что-то при вызове onTextEdited.
Проблема теперь в том, что что все 3 _lineEdit#->text().toDouble(); дают мне значение по умолчанию 0 независимо от того, что в них находится. Что могло вызвать эту проблему и можно ли ее исправить?
Подробнее здесь: https://stackoverflow.com/questions/783 ... r-function