PDA

View Full Version : Status Bar



waynew
20th November 2009, 23:25
Is it possible to pass a value to the status bar in the main window with a signal/slot? From a dialog? I'm having trouble figuring out the right code.
Any suggestions or pointers to examples?

wysota
21st November 2009, 00:53
What kind of value? What do you want to do with it?

waynew
21st November 2009, 01:20
Thanks Wysota. I have a function that updates a QString/varchar database field.
When that changes, I want to display the new value in the status bar as a permanent message preceded by some text. The text appears ok, but when I try code to pass the value, I can't get a compile. Just my lack of Qt knowledge, but I can't seem to find any references to doing this. Can't find anything in my books or online.
Here are some code snippets of what I tried:



class ControlDB:public QObject
{
Q_OBJECT

public:
ControlDB(QObject *parent = 0);
void makeControlDB();
void setLastLog(QString);
void setOper(QString);
QString getLastLog();
QString getOper();

signals:
void valueChanged(QString newValue);
}

//cpp file
ControlDB::ControlDB(QObject *parent)
{

}
void ControlDB::setOper(QString oper) {
//some code to change the oper value
emit valueChanged(oper);
}

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
setupActions();

mStatLabel = new QLabel;
statusBar()->addPermanentWidget(mStatLabel);
ControlDB ctrl;
connect(&ctrl, SIGNAL(valueChanged(QString)), this, SLOT(updateStats(QString)));
updateStats(QString);
}

void MainWindow::updateStats(oper)
{
QString operOutput = "Current op is " + oper;
mStatLabel->setText(operOutput);
}


Thanks for any assistance.

wysota
21st November 2009, 09:07
What is the error you get?

Line #37 of the code above is surely incorrect. It should probably say:

updateStats(QString());