Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2011-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#include <qt/qvalidatedlineedit.h>7#include <qt/bitcoinaddressvalidator.h>8#include <qt/guiconstants.h>10QValidatedLineEdit::QValidatedLineEdit(QWidget* parent)11: QLineEdit(parent)12{13connect(this, &QValidatedLineEdit::textChanged, this, &QValidatedLineEdit::markValid);14}16void QValidatedLineEdit::setText(const QString& text)17{18QLineEdit::setText(text);19checkValidity();20}22void QValidatedLineEdit::setValid(bool _valid)23{24if(_valid == this->valid)25{26return;27}29if(_valid)30{31setStyleSheet("");32}33else34{35setStyleSheet("QValidatedLineEdit { " STYLE_INVALID "}");36}37this->valid = _valid;38}40void QValidatedLineEdit::focusInEvent(QFocusEvent *evt)41{42// Clear invalid flag on focus43setValid(true);45QLineEdit::focusInEvent(evt);46}48void QValidatedLineEdit::focusOutEvent(QFocusEvent *evt)49{50checkValidity();52QLineEdit::focusOutEvent(evt);53}55void QValidatedLineEdit::markValid()56{57// As long as a user is typing ensure we display state as valid58setValid(true);59}61void QValidatedLineEdit::clear()62{63setValid(true);64QLineEdit::clear();65}67void QValidatedLineEdit::setEnabled(bool enabled)68{69if (!enabled)70{71// A disabled QValidatedLineEdit should be marked valid72setValid(true);73}74else75{76// Recheck validity when QValidatedLineEdit gets enabled77checkValidity();78}80QLineEdit::setEnabled(enabled);81}83void QValidatedLineEdit::checkValidity()84{85if (text().isEmpty())86{87setValid(true);88}89else if (hasAcceptableInput())90{91setValid(true);93// Check contents on focus out94if (checkValidator)95{96QString address = text();97int pos = 0;98if (checkValidator->validate(address, pos) == QValidator::Acceptable)99setValid(true);100else101setValid(false);102}103}104else105setValid(false);107Q_EMIT validationDidChange(this);108}110void QValidatedLineEdit::setCheckValidator(const QValidator *v)111{112checkValidator = v;113checkValidity();114}116bool QValidatedLineEdit::isValid()117{118// use checkValidator in case the QValidatedLineEdit is disabled119if (checkValidator)120{121QString address = text();122int pos = 0;123if (checkValidator->validate(address, pos) == QValidator::Acceptable)124return true;125}127return valid;128}130#include <moc_qvalidatedlineedit.cpp>
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.