I'm trying to set up a static function and QLabel so that non-Qt parts of my application can call this function and change the setNum() value of the QLabel. I've done it like so:
//--window.h
{
Q_OBJECT
public:
Window();
static void setText(int value);
// etc...
//--window.cpp
#include <QtGui>
#include "window.h"
vuXLocLabel->setText("hello");
void Window::setText(int value)
{
vuXLocLabel->setNum(value);
//vuXLocLabel->setText("goodbye");
qDebug(" HERE %d", value);
}
//--window.h
class Window : public QWidget
{
Q_OBJECT
public:
Window();
static void setText(int value);
// etc...
//--window.cpp
#include <QtGui>
#include "window.h"
static QLabel *vuXLocLabel=0;
vuXLocLabel = new QLabel;
vuXLocLabel->setText("hello");
void Window::setText(int value)
{
vuXLocLabel->setNum(value);
//vuXLocLabel->setText("goodbye");
qDebug(" HERE %d", value);
}
To copy to clipboard, switch view to plain text mode
The QLabel is displayed correctly initially: "hello". But when I call
Window::setText(value);
from the non-Qt part of the program, the value is sent and qDebug("HERE %d") is called (with correct value), but the QLabel isn't changed (using either setNum() or setText().)
I also tried setting up the vuXLocLabel like so:
//--window.h
//--window.cpp
QLabel *Window
::vuXLocLabel=0;
//--window.h
static QLabel *vuXLocLabel;
//--window.cpp
QLabel *Window::vuXLocLabel=0;
To copy to clipboard, switch view to plain text mode
but got the same result: code compiled, program didn't crash, but setNum/setText didn't work. Any insights greatly appreciated. (of course )
Bookmarks