QLabel not showing text

  • Ok, I have a QDockeWidget class with some widgets inside. One of them is a QLabel. I've created a slot method to update my QLabel each time a mouse release event occurs.
    The mouse release event is signaling this class via some other class that emits a signl that I created. This line of code resides in my QMainWindow:
    connect(_viewPanel, SIGNAL(MouseRelease(QPointF,int)), _toolPanel, SLOT(ShowMeasures(QPointF)));

    The problem is it's not updating. I'll post code:
    MeasureToolPanel::MeasureToolPanel(QWidget *parent) : QDockWidget(parent), _measureInfos(NULL)

    MeasureToolPanel::MeasureToolPanel(const QString &title, QWidget *parent) : QDockWidget(title, parent), _measureInfos(NULL)

    void MeasureToolPanel::Setup()
    _widget = new QWidget();
    _windowLayout = new QVBoxLayout();
    _measureInfos = new QLabel();



    void MeasureToolPanel::ShowMeasures(const QPointF& latLong)
    _points << latLong;

    if(_points.count() >= 2)
        QString measures;
        measures = "KM: "+QString("%1").arg(MathUtils::DistanceInKilometers(_points.at(0), _points.at(1)))+"\n"+
                   "NM: "+QString("%1").arg(MathUtils::DistanceInNauticalMiles(_points.at(0), _points.at(1)));


    I print my QString to see if it's empty and it's not. The information is there. The only problem is the update of QLabel.
    I've tried to solve this calling qApp->procesEvents() and QLabel::update method. None of this works.

  • Hi!

    I'd say that the problem is when connecting. Receiving function needs to have the same arguments as emitting function.

    If running in debug, Qt Creator should wrote that was unable to connect those two functions.

    Check if updating code even gets executed.

  • The connect looks ok to me. The receiving slot has to have the same number or fewer arguments than the calling slot, so long as those that match up have the same signature.

    I'd be curious to see if the label were set up properly. Does it have default text? Is there a chance that the label is too small to be visible if it has text set? You could try setting default text in the label first to make sure that it is functioning properly.

    I also assume that setVisible() eventually gets set to true somewhere...

  • Guys, sorry for the question.
    I was creating 2 instances of the same object and the second one has been updated. Removed the first and shows the correct one, solves the problem.

    Sorry again this thing has driven me crazy.

  • Glad you got it working :-) Be sure and edit your first post to add [Solved] to the title.

Log in to reply