Results 1 to 11 of 11

Thread: QLabel setText Problem

  1. #1
    Join Date
    Sep 2007
    Posts
    20
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QLabel setText Problem

    Hello
    I made a simple form in the Qt Designer, 4 QLabel's and 1 Process bar.
    I am trying to feed the QLabela file name to be displayed in the my Dialog.

    Qt Code:
    1. labelFileName->setText(filename);
    To copy to clipboard, switch view to plain text mode 

    no matter what I do, I just can't get it to print the line, the only way I got it to work was to place a statement after setupUI.
    Qt Code:
    1. setupUi(this)
    2. labelFileName->setText("Test");
    To copy to clipboard, switch view to plain text mode 


    My Question is , why doesn't my statement work.

    Thanks for your time .

    Patrick.
    Last edited by jacek; 31st October 2007 at 23:12. Reason: changed [qtclass] to [code]

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLabel setText Problem

    Where did you try to place that line?

  3. #3
    Join Date
    Sep 2007
    Posts
    20
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLabel setText Problem

    In the dialog containing the QLabel * labelFilename

    hope that helps..

    thanks for the reply!

    Patrick.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLabel setText Problem

    Could you post an example of non-working code?

  5. #5
    Join Date
    Sep 2007
    Posts
    20
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Red face Re: QLabel setText Problem

    Qt Code:
    1. /*
    2.   ProcessingDlg.Cpp
    3. */
    4.  
    5. #include "MainWindow.h"
    6. #include <QtGui>
    7. #include <QCloseEvent >
    8. #include "ProcessingDlg.h"
    9. #include "Config.h"
    10.  
    11. ProcessingDlg::ProcessingDlg(QWidget *parent, MainWindow *h)
    12. : QDialog(parent),help(h)
    13. {
    14. setupUi(this);
    15. }
    16.  
    17. void ProcessingDlg::closeEvent(QCloseEvent *m_pevent)
    18. {
    19. help->m_pProcessDlg = false;
    20. delete help->m_pProcessDlg;
    21. m_pevent->accept();
    22. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. /*
    2.   ProcessingDlg.h
    3. */
    4.  
    5. #ifndef PROCESSINGDLG_H
    6. #define PROCESSINGDLG_H
    7.  
    8. #include"ui_Processing.h"
    9.  
    10. class MainWindow;
    11. class QLabel;
    12.  
    13. class ProcessingDlg : public QDialog, public Ui::Process
    14. {
    15. Q_OBJECT
    16.  
    17. public:
    18. ProcessingDlg(QWidget *parent,MainWindow *h);
    19. MainWindow *help;
    20.  
    21. protected:
    22. void closeEvent(QCloseEvent *m_pevent);
    23.  
    24. public slots:
    25.  
    26. private:
    27. Ui::Process ui;
    28.  
    29. public:
    30.  
    31. };
    32.  
    33. #endif
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. if(!m_pProcessDlg)
    2. m_pProcessDlg = new ProcessingDlg(m_pTab,this);
    3.  
    4. // Make FIle List of Directory
    5. QFileInfoList m_pFinfo = CurrentDir.entryInfoList();
    6.  
    7. m_pEntries = m_pFinfo.count();
    8.  
    9. m_pProcessDlg->progressBar->setMaximum(m_pEntries);
    10. m_pProcessDlg->progressBar->setValue(m_pCurrentEnt);
    11.  
    12. if(!CurrentDir.cd(DirPath))
    13. {
    14. QMessageBox::information(this,tr("Error"),tr("Can't Cd into %1").arg(DirPath));
    15. return false;
    16. }
    17.  
    18. m_pProcessDlg->labelDirectory->setText(DirPath);
    To copy to clipboard, switch view to plain text mode 

    Hope this helps , thanks again for your time , it's greatly appreciated!
    Patrick
    Last edited by jacek; 31st October 2007 at 23:50. Reason: changed [qtclass] to [code]

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLabel setText Problem

    Quote Originally Posted by pmabie View Post
    help->m_pProcessDlg = false;
    delete help->m_pProcessDlg;
    This is wrong --- the second line should be first.

    Quote Originally Posted by pmabie View Post
    if(!m_pProcessDlg)
    m_pProcessDlg = new ProcessingDlg(m_pTab,this);
    ...
    m_pProcessDlg->labelDirectory->setText(DirPath);
    Do you invoke exec() on m_pProcessDlg anywhere?

    P.S. Please use [code] tags for code snippets, not [qtclass]. The latter is for linking to Qt docs.

  7. #7
    Join Date
    Sep 2007
    Posts
    20
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLabel setText Problem

    Really sorry , I will remember that .

    I am doing a show();

    Patrick.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLabel setText Problem

    Quote Originally Posted by pmabie View Post
    I am doing a show();
    OK, then maybe you declare m_pProcessDlg more than once?

  9. #9
    Join Date
    Sep 2007
    Posts
    20
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLabel setText Problem

    I will check on that , but I pretty sure that it's in my mainwindow.h

    Thanks!

  10. #10
    Join Date
    Sep 2007
    Posts
    20
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLabel setText Problem

    Checked it out , only one time, I tried to setText before the show() worked fine , after I show it , I lose contact ....

    thanks alot for you time!

    Patrick.

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLabel setText Problem

    Then maybe you have some kind of a loop that blocks the event loop and you simply can't see that the text was changed.

Similar Threads

  1. Problem with QLabel and setText
    By jambrek in forum Qt Programming
    Replies: 7
    Last Post: 31st October 2007, 16:02
  2. Problem with QLabel & mouseEvent
    By harakiri in forum Newbie
    Replies: 5
    Last Post: 26th May 2007, 13:54
  3. Problem with QLineEdit and setText
    By Elmo23x in forum Qt Programming
    Replies: 8
    Last Post: 12th April 2007, 12:35
  4. Replies: 1
    Last Post: 26th November 2006, 09:32
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.