Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Manually calling lineEdit's textChanged



  • How to force call of lineEdit's textChanged at startup?
    The workaround is:
    @MainWindow::MainWindow(QWidget *parent) :
    ...
    QString s = ui->vectorEdit->text()+" ";
    ui->vectorEdit->setText(s);@

    How to do it properly? And without adding a space.


  • Moderators

    -You can subclass the QLineEdit and make it emit the signal in its constructor-

    Edit: Sorry, I just realized you can't emit signals in a constructor, because you don't have time to connect it to a slot first!



  • And how to use such subclasses in Designer? If there is no way of inheritance?


  • Moderators

    You can "promote" your custom widget to use it in Designer (see http://qt-project.org/doc/qt-4.8/designer-using-custom-widgets.html#promoting-widgets ). You can't see it in Designer though; there will be a blank space.

    Without using inheritance, you can create a signal in your QMainWindow, connect that signal to QLineEdit::textChanged(), and make your QMainWindow emit that signal.

    @
    MainWindow : public QMainWindow
    {
    ...
    signals:
    void started(QString);

    public:
    MainWindow(QWidget *parent) : QWidget(parent)
    {
    connect(this, SIGNAL(started(QString)),
    ui->vectorEdit, SIGNAL(textChanged(QString)));

        emit started(ui->vectorEdit->text());
    }
    

    };
    @


  • Moderators

    Sorry, I just realized you can’t emit signals in a constructor, because you don’t have time to connect it to a slot first!


Log in to reply