Results 1 to 8 of 8

Thread: Clear text of LineEdit

  1. #1
    Join Date
    May 2012
    Posts
    23
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Clear text of LineEdit

    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??

    Qt Code:
    1. void MainWindow::checkImageSize()
    2. {
    3. // host and cover variables are of type int
    4. if(host < cover)
    5. {
    6. QMessageBox::about(this, tr("Error"),
    7. tr("Size of <b>Host Image</b> must be greater than the <b>Cover Image</b>!"));
    8.  
    9. ui->hostImageLEdit->clear();
    10. ui->coverImageLEdit->clear();
    11. }
    12. else if(host == cover)
    13. {
    14. QMessageBox::about(this, tr("Error"),
    15. tr("Size of <b>Host Image</b> and <b>Cover Image</b> are the same!"));
    16.  
    17. ui->hostImageLEdit->clear();
    18. ui->coverImageLEdit->clear();
    19. }
    20. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Clear text of LineEdit

    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.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    May 2012
    Posts
    23
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Clear text of LineEdit

    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

    Qt Code:
    1. std::cout << &ui->coverImageLEdit;
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Clear text of LineEdit

    you dont want the address of the pointer, you want the address of the lineedit, which is just ui->coverImageLEdit (no ampersand).
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  5. #5
    Join Date
    May 2012
    Posts
    23
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Clear text of LineEdit

    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??

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Clear text of LineEdit

    Show us the constructor for your class.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    May 2012
    Posts
    23
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Clear text of LineEdit

    Here it is
    Qt Code:
    1. void setupUi(QMainWindow *MainWindow)
    2. {
    3. if (MainWindow->objectName().isEmpty())
    4. MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
    5.  
    6. MainWindow->move(500, 250);
    7.  
    8. action_Help = new QAction(MainWindow);
    9. action_Help->setObjectName(QString::fromUtf8("action_Help"));
    10. action_About = new QAction(MainWindow);
    11. action_About->setObjectName(QString::fromUtf8("action_About"));
    12.  
    13. centralWidget = new QWidget(MainWindow);
    14. centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
    15.  
    16. tabWidgetWatermark = new QTabWidget(centralWidget);
    17. tabWidgetWatermark->setObjectName(QString::fromUtf8("tabWidgetWatermark"));
    18. tabWidgetWatermark->setGeometry(QRect(10, 0, 441, 191));
    19.  
    20. tab = new QWidget();
    21. tab->setObjectName(QString::fromUtf8("tab"));
    22.  
    23. hostImageBtn = new QPushButton(tab);
    24. hostImageBtn->setObjectName(QString::fromUtf8("hostImageBtn"));
    25. hostImageBtn->setGeometry(QRect(20, 20, 151, 27));
    26.  
    27. coverImageBtn = new QPushButton(tab);
    28. coverImageBtn->setObjectName(QString::fromUtf8("coverImageBtn"));
    29. coverImageBtn->setGeometry(QRect(20, 60, 151, 27));
    30.  
    31. applyWatermarkBtn = new QPushButton(tab);
    32. applyWatermarkBtn->setObjectName(QString::fromUtf8("applyWatermarkBtn"));
    33. applyWatermarkBtn->setGeometry(QRect(200, 100, 151, 27));
    34.  
    35. hostImageLEdit = new QLineEdit(tab);
    36. hostImageLEdit->setObjectName(QString::fromUtf8("hostImageLEdit"));
    37. hostImageLEdit->setGeometry(QRect(190, 20, 191, 27));
    38. hostImageLEdit->setReadOnly(TRUE);
    39.  
    40. coverImageLEdit = new QLineEdit(tab);
    41. coverImageLEdit->setObjectName(QString::fromUtf8("coverImageLEdit"));
    42. coverImageLEdit->setGeometry(QRect(190, 60, 191, 27));
    43. coverImageLEdit->setReadOnly(TRUE);
    44.  
    45. tabWidgetWatermark->addTab(tab, QString());
    46. tab_2 = new QWidget();
    47. tab_2->setObjectName(QString::fromUtf8("tab_2"));
    48.  
    49. browseExtractBtn = new QPushButton(tab_2);
    50. browseExtractBtn->setObjectName(QString::fromUtf8("browseExtractBtn"));
    51. browseExtractBtn->setGeometry(QRect(20, 20, 151, 27));
    52.  
    53. extractBtn = new QPushButton(tab_2);
    54. extractBtn->setObjectName(QString::fromUtf8("extractBtn"));
    55. extractBtn->setGeometry(QRect(210, 60, 151, 27));
    56.  
    57. extractLEdit = new QLineEdit(tab_2);
    58. extractLEdit->setObjectName(QString::fromUtf8("extractLEdit"));
    59. extractLEdit->setGeometry(QRect(190, 20, 191, 27));
    60. extractLEdit->setReadOnly(TRUE);
    61.  
    62. tabWidgetWatermark->addTab(tab_2, QString());
    63. MainWindow->setCentralWidget(centralWidget);
    64.  
    65. menuBar = new QMenuBar(MainWindow);
    66. menuBar->setObjectName(QString::fromUtf8("menuBar"));
    67. menuBar->setGeometry(QRect(0, 0, 463, 25));
    68.  
    69. menu_Help = new QMenu(menuBar);
    70. menu_Help->setObjectName(QString::fromUtf8("menu_Help"));
    71.  
    72. MainWindow->setMenuBar(menuBar);
    73. mainToolBar = new QToolBar(MainWindow);
    74. mainToolBar->setObjectName(QString::fromUtf8("mainToolBar"));
    75.  
    76. MainWindow->addToolBar(Qt::TopToolBarArea, mainToolBar);
    77. statusBar = new QStatusBar(MainWindow);
    78. statusBar->setObjectName(QString::fromUtf8("statusBar"));
    79. MainWindow->setStatusBar(statusBar);
    80.  
    81. menuBar->addAction(menu_Help->menuAction());
    82. menu_Help->addSeparator();
    83. menu_Help->addAction(action_Help);
    84. menu_Help->addAction(action_About);
    85.  
    86. retranslateUi(MainWindow);
    87.  
    88. tabWidgetWatermark->setCurrentIndex(0);
    89.  
    90.  
    91. QMetaObject::connectSlotsByName(MainWindow);
    92. } // setupUi
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Clear text of LineEdit

    That's not a constructor.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. clear text in QDateEdit
    By dyams in forum Qt Programming
    Replies: 6
    Last Post: 31st August 2010, 22:30
  2. lineEdit's setSelection - How to show more text?
    By squidge in forum Qt Programming
    Replies: 3
    Last Post: 30th January 2010, 17:22
  3. Get text from dynamic lineedit
    By wirasto in forum Qt Programming
    Replies: 1
    Last Post: 13th January 2010, 18:56
  4. Enabling buttons when lineEdit has text
    By k12yp70n in forum Newbie
    Replies: 4
    Last Post: 29th May 2009, 07:18
  5. Lineedit text change signal
    By zgulser in forum Qt Tools
    Replies: 2
    Last Post: 19th January 2009, 13:38

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.