Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QComboBox LineEdit crashing
Forum Updated to NodeBB v4.3 + New Features

QComboBox LineEdit crashing

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 664 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Reghu_Att
    wrote on last edited by
    #1

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

    #include <QComboBox>
    #include <QLineEdit>
    ui->cmbTest->lineEdit()->setAlignment(Qt::AlignHCenter);
    

    I found out that the function:

    ui->cmbTest->lineEdit();
    

    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.

    JonBJ 1 Reply Last reply
    0
    • R Reghu_Att

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

      #include <QComboBox>
      #include <QLineEdit>
      ui->cmbTest->lineEdit()->setAlignment(Qt::AlignHCenter);
      

      I found out that the function:

      ui->cmbTest->lineEdit();
      

      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.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Reghu_Att
      Read the docs! :)

      https://doc.qt.io/qt-5/qcombobox.html#lineEdit

      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.

      https://doc.qt.io/qt-5/qcombobox.html#editable-prop

      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!)

      R 1 Reply Last reply
      5
      • JonBJ JonB

        @Reghu_Att
        Read the docs! :)

        https://doc.qt.io/qt-5/qcombobox.html#lineEdit

        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.

        https://doc.qt.io/qt-5/qcombobox.html#editable-prop

        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!)

        R Offline
        R Offline
        Reghu_Att
        wrote on last edited by
        #3

        @jonb

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

        ui->cmbTest->lineEdit()->setReadOnly(true);
        ui->cmbTest->lineEdit()->setAlignment(Qt::AlignHCenter);
        

        Regards.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved