PDA

View Full Version : Clear text of LineEdit



stbb24
10th June 2012, 09:47
I have this code that checks the sizes of the images

If the host image is less than the cover image a message box will appear and will clear the text of the line edits of the hostImageLEdit and the coverImageLEdit. It will also do the same thing when the host image and cover image has the same sizes.

But when I run the program to check it only clears the text of the hostImageLEdit and not the coverImageLEdit.

It looks logically correct since it's able to clear the hostImageLEdit but clearly there's something wrong since it doesn't clear out the text of the coverImageLEdit. Any comments??



void MainWindow::checkImageSize()
{
// host and cover variables are of type int
if(host < cover)
{
QMessageBox::about(this, tr("Error"),
tr("Size of <b>Host Image</b> must be greater than the <b>Cover Image</b>!"));

ui->hostImageLEdit->clear();
ui->coverImageLEdit->clear();
}
else if(host == cover)
{
QMessageBox::about(this, tr("Error"),
tr("Size of <b>Host Image</b> and <b>Cover Image</b> are the same!"));

ui->hostImageLEdit->clear();
ui->coverImageLEdit->clear();
}
}

amleto
10th June 2012, 11:02
Then coverImageLEdit is not pointing to the line edit you think it is. If the pointer was invalid, you would get a crash (almost certainly).

I suggest you look at all references of coverImageLEdit and see if you assign it any different instances.


You can easily check the address of the coverImageLEdit instance made in setupUi, and then check again the address of the lineedit that is being cleared in your function to confirm.

stbb24
10th June 2012, 22:05
so I check the address of the coverImageLEdit in the setupUi and it was able to return an address but when I check the address of the coverImageLEdit inside the checkImageSize() function it doesn't return anything

I used this code


std::cout << &ui->coverImageLEdit;

amleto
10th June 2012, 23:21
you dont want the address of the pointer, you want the address of the lineedit, which is just ui->coverImageLEdit (no ampersand).

stbb24
12th June 2012, 03:07
i check the addresses of the two and their not the same in the setupUi the address is 0x86498e0 and in the checkImage() function the address is 0x8c24710. I also checked my ui_mainwindow.h and everything seems to be declared and used properly.

Any comments on how to fix this??

wysota
12th June 2012, 09:40
Show us the constructor for your class.

stbb24
12th June 2012, 13:21
Here it is


void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));

MainWindow->move(500, 250);

action_Help = new QAction(MainWindow);
action_Help->setObjectName(QString::fromUtf8("action_Help"));
action_About = new QAction(MainWindow);
action_About->setObjectName(QString::fromUtf8("action_About"));

centralWidget = new QWidget(MainWindow);
centralWidget->setObjectName(QString::fromUtf8("centralWidget"));

tabWidgetWatermark = new QTabWidget(centralWidget);
tabWidgetWatermark->setObjectName(QString::fromUtf8("tabWidgetWatermark"));
tabWidgetWatermark->setGeometry(QRect(10, 0, 441, 191));

tab = new QWidget();
tab->setObjectName(QString::fromUtf8("tab"));

hostImageBtn = new QPushButton(tab);
hostImageBtn->setObjectName(QString::fromUtf8("hostImageBtn"));
hostImageBtn->setGeometry(QRect(20, 20, 151, 27));

coverImageBtn = new QPushButton(tab);
coverImageBtn->setObjectName(QString::fromUtf8("coverImageBtn"));
coverImageBtn->setGeometry(QRect(20, 60, 151, 27));

applyWatermarkBtn = new QPushButton(tab);
applyWatermarkBtn->setObjectName(QString::fromUtf8("applyWatermarkBtn"));
applyWatermarkBtn->setGeometry(QRect(200, 100, 151, 27));

hostImageLEdit = new QLineEdit(tab);
hostImageLEdit->setObjectName(QString::fromUtf8("hostImageLEdit"));
hostImageLEdit->setGeometry(QRect(190, 20, 191, 27));
hostImageLEdit->setReadOnly(TRUE);

coverImageLEdit = new QLineEdit(tab);
coverImageLEdit->setObjectName(QString::fromUtf8("coverImageLEdit"));
coverImageLEdit->setGeometry(QRect(190, 60, 191, 27));
coverImageLEdit->setReadOnly(TRUE);

tabWidgetWatermark->addTab(tab, QString());
tab_2 = new QWidget();
tab_2->setObjectName(QString::fromUtf8("tab_2"));

browseExtractBtn = new QPushButton(tab_2);
browseExtractBtn->setObjectName(QString::fromUtf8("browseExtractBtn"));
browseExtractBtn->setGeometry(QRect(20, 20, 151, 27));

extractBtn = new QPushButton(tab_2);
extractBtn->setObjectName(QString::fromUtf8("extractBtn"));
extractBtn->setGeometry(QRect(210, 60, 151, 27));

extractLEdit = new QLineEdit(tab_2);
extractLEdit->setObjectName(QString::fromUtf8("extractLEdit"));
extractLEdit->setGeometry(QRect(190, 20, 191, 27));
extractLEdit->setReadOnly(TRUE);

tabWidgetWatermark->addTab(tab_2, QString());
MainWindow->setCentralWidget(centralWidget);

menuBar = new QMenuBar(MainWindow);
menuBar->setObjectName(QString::fromUtf8("menuBar"));
menuBar->setGeometry(QRect(0, 0, 463, 25));

menu_Help = new QMenu(menuBar);
menu_Help->setObjectName(QString::fromUtf8("menu_Help"));

MainWindow->setMenuBar(menuBar);
mainToolBar = new QToolBar(MainWindow);
mainToolBar->setObjectName(QString::fromUtf8("mainToolBar"));

MainWindow->addToolBar(Qt::TopToolBarArea, mainToolBar);
statusBar = new QStatusBar(MainWindow);
statusBar->setObjectName(QString::fromUtf8("statusBar"));
MainWindow->setStatusBar(statusBar);

menuBar->addAction(menu_Help->menuAction());
menu_Help->addSeparator();
menu_Help->addAction(action_Help);
menu_Help->addAction(action_About);

retranslateUi(MainWindow);

tabWidgetWatermark->setCurrentIndex(0);


QMetaObject::connectSlotsByName(MainWindow);
} // setupUi

wysota
12th June 2012, 13:30
That's not a constructor.