Important: Please read the Qt Code of Conduct -

QComboBox LineEdit crashing

  • Hello,
    I'm trying to set the alignment in my QComboBox line edit field.

    #include <QComboBox>
    #include <QLineEdit>

    I found out that the function:


    Was actually returning a null pointer. That is when I do this:

    QLineEdit *tmp = ui->cmbTest->lineEdit();

    tmp = NULL

    What am I doing wrong?

    Thank you.

  • @Reghu_Att
    Read the docs! :)

    Returns the line edit used to edit items in the combobox, or nullptr if there is no line edit.

    Only editable combo boxes have a line edit.

    This property holds whether the combo box can be edited by the user

    By default, this property is false. The effect of editing depends on the insert policy.

    (So, to be clear, if you have not gone ui->cmbTest->setEditable(true) you won't have a line edit!)

  • @jonb

    Hello. Thanks for the response.
    I ended up making the combo boxes editable in QtCreator and then doing this:



Log in to reply