View Full Version : QLabel setText Problem
pmabie
31st October 2007, 22:50
Hello
I made a simple form in the Qt Designer, 4 QLabel's and 1 Process bar.
I am trying to feed the QLabel a file name to be displayed in the my Dialog.
labelFileName->setText(filename);:(
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.
setupUi(this)
labelFileName->setText("Test");:)
My Question is , why doesn't my statement work.
Thanks for your time .
Patrick.
jacek
31st October 2007, 23:18
Where did you try to place that line?
pmabie
31st October 2007, 23:36
In the dialog containing the QLabel * labelFilename
hope that helps..
thanks for the reply!
Patrick.
jacek
31st October 2007, 23:39
Could you post an example of non-working code?
pmabie
31st October 2007, 23:47
/*
ProcessingDlg.Cpp
*/
#include "MainWindow.h"
#include <QtGui>
#include <QCloseEvent >
#include "ProcessingDlg.h"
#include "Config.h"
ProcessingDlg::ProcessingDlg(QWidget *parent, MainWindow *h)
: QDialog(parent),help(h)
{
setupUi(this);
}
void ProcessingDlg::closeEvent(QCloseEvent *m_pevent)
{
help->m_pProcessDlg = false;
delete help->m_pProcessDlg;
m_pevent->accept();
}
/*
ProcessingDlg.h
*/
#ifndef PROCESSINGDLG_H
#define PROCESSINGDLG_H
#include"ui_Processing.h"
class MainWindow;
class QLabel;
class ProcessingDlg : public QDialog, public Ui::Process
{
Q_OBJECT
public:
ProcessingDlg(QWidget *parent,MainWindow *h);
MainWindow *help;
protected:
void closeEvent(QCloseEvent *m_pevent);
public slots:
private:
Ui::Process ui;
public:
};
#endif
if(!m_pProcessDlg)
m_pProcessDlg = new ProcessingDlg(m_pTab,this);
// Make FIle List of Directory
QFileInfoList m_pFinfo = CurrentDir.entryInfoList();
m_pEntries = m_pFinfo.count();
m_pProcessDlg->progressBar->setMaximum(m_pEntries);
m_pProcessDlg->progressBar->setValue(m_pCurrentEnt);
if(!CurrentDir.cd(DirPath))
{
QMessageBox::information(this,tr("Error"),tr("Can't Cd into %1").arg(DirPath));
return false;
}
m_pProcessDlg->labelDirectory->setText(DirPath);
Hope this helps , thanks again for your time , it's greatly appreciated!
Patrick
jacek
1st November 2007, 00:05
help->m_pProcessDlg = false;
delete help->m_pProcessDlg;
This is wrong --- the second line should be first.
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.
pmabie
1st November 2007, 00:10
Really sorry , I will remember that .
I am doing a show();
Patrick.
jacek
1st November 2007, 00:13
I am doing a show();
OK, then maybe you declare m_pProcessDlg more than once?
pmabie
1st November 2007, 00:17
I will check on that , but I pretty sure that it's in my mainwindow.h :)
Thanks!
pmabie
1st November 2007, 00:26
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.
jacek
1st November 2007, 23:32
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.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.