Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QLabel not showing text
QtWS25 Last Chance

QLabel not showing text

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 6.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    qtBeginner
    wrote on last edited by
    #1

    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)
    {
    Setup();
    }

    MeasureToolPanel::MeasureToolPanel(const QString &title, QWidget *parent) : QDockWidget(title, parent), _measureInfos(NULL)
    {
    Setup();
    }

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

    this->setWindowTitle("Measures");
    
    _windowLayout->addWidget(_measureInfos);
    _widget->setLayout(_windowLayout);
    this->setWidget(_widget);
    this->setFloating(true);
    this->setVisible(false);
    

    }

    //THIS IS MY SLOT
    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)));
    
        _measureInfos->setText(measures);
        _points.clear();
    }
    

    }
    @

    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.

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jake007
      wrote on last edited by
      #2

      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.


      Code is poetry

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mlong
        wrote on last edited by
        #3

        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...

        Software Engineer
        My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          qtBeginner
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mlong
            wrote on last edited by
            #5

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

            Software Engineer
            My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved