简体   繁体   中英

Issue with QLineEdit

I'm doing a Qt project where I'm having some QLineEdit that whatever I put into them it doesn't get any data, and in others I don't have this problem. Also in some of them if I only put in there one char it still thinks that I have nothing and then I cant erase that char. I tried using textChanged and editingFinished signals but it still doesn't work. This is what I tried:

void MainWindow::on_numExt_textChanged(const QString &arg1)
{
    ui->numExt->setText( arg1 );
}

where numExt is the QLineEdit name, sometimes I have to press enter and I get the text but it doesn't work all the times

this is the declaration of the QLineEdit :

<widget class="QLineEdit" name="numExt">
    <property name="font">
        <font>
            <pointsize>6</pointsize>
        </font>
    </property>
 </widget>

and in the ui_mainwindow.h file appears like this:

numExt = new QLineEdit(frame_5);
numExt->setObjectName(QString::fromUtf8("numExt"));
numExt->setFont(font);

here im used it to save its value into a db

insertQuery = "update content set calle='" + ui->calle->text().toUtf8() + "', numExt='"+ ui->numExt->text().toUtf8() +"', numInt='"+ ui->numInt->text().toUtf8() +"', colonia='" + ui->colonia->text().toUtf8() + "', CP='" + ui->CP->text().toUtf8() + "' where folio='" + ui->Folio->text().toUtf8() + "'"; 
query.exec(insertQuery);

I didn't change any attribute of the form.

My goal is to get the text that is in the qlineedit, it doesn't matter if I input 1 character or more.

Sounds like you need to run a debugger like the one in QtCreator and see what your values are when you:

  1. type something into the field
  2. whats being sent back to the field

This will narrow it down more as to where the issue lies.
ie: If it's in the saving of the data, or the retrieving of the data.

You're creating a race condition with the above code. If you're actually binding a signal/slot to modifying the same object you'll run into trouble. You generally shouldn't be changing the text that is being edited right at the same time it's being edited. To make it more complex, remember that there is no guarantee that the LineEdit block won't emit multiple signals before you slot actually gets called to handle them. It all depends on when the event loop actually has the break to process everything.

In short: don't do that. Describe instead what your end goal is instead and maybe we can find the real source of your problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM