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. Get Text from a Qlabel from QWidget inside QMdiAreaSubWindow, when window is active/selected?

Get Text from a Qlabel from QWidget inside QMdiAreaSubWindow, when window is active/selected?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 546 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.
  • H Offline
    H Offline
    Hermes22
    wrote on last edited by
    #1

    How to get text from a QLabel from QWidget which is displayed in a QMdiAreaSubWindow? I need the text in mainwindow.cpp. Any tips/suggestion are welcome....

    In MainWindow i have:

    void MainWindow::on_mdiArea_subWindowActivated(QMdiSubWindow *arg1)
    {
        QWidget *widget = arg1->widget();
        tabs *tab = new tabs(widget);
        QString tabname = tab->getData();
        qDebug() << "tabname:" << tabname;
    }
    

    in tabs.h:

    #ifndef TABS_H
    #define TABS_H
    
    #include <QWidget>
    
    
    namespace Ui {
    class tabs;
    }
    
    class tabs : public QWidget
    {
        Q_OBJECT
    
    public:
        explicit tabs(QWidget *parent = nullptr);
        ~tabs();
        void sendData(QString name, QString time, QString date, QString country, QString province, QString city, QString longitude, QString latitude, QString timezone, QString ut, QString houseSys, QString houseSysOpt, QString lonhemi, QString longitude_deg, QString longitude_min, QString lathemi, QString latitude_deg, QString latitude_min);
        QString getData();
    
    private:
        Ui::tabs *ui;
    
        QString tabName;
        QString tabTime;
        QString tabDate;
        QString tabCountry;
        QString tabProvince;
        QString tabCity;
        QString tabLongitude;
        QString tabLatitude;
        QString tabTimezone;
        QString tabUt;
        QString tabLonHemi;
        QString tabLongitude_deg;
        QString tabLongitude_min;
        QString tabLatHemi;
        QString tabLatitude_deg;
        QString tabLatitude_min;
        QString tabHouseSys;
        QString tabHouseSysOpt;
    
    };
    
    #endif // TABS_H
    

    in tabs.cpp:

    #include "tabs.h"
    #include "ui_tabs.h"
    
    #include <QDebug>
    #include <mainwindow.h>
    
    tabs::tabs(QWidget *parent) :
        QWidget(parent),
        ui(new Ui::tabs)
    {
        ui->setupUi(this);
    
        ui->label_24->hide();
    }
    
    void tabs::sendData(QString name, QString time, QString date, QString country, QString province, QString city, QString longitude, QString latitude, QString timezone, QString ut, QString houseSys, QString houseSysOpt, QString lonhemi, QString longitude_deg, QString longitude_min, QString lathemi, QString latitude_deg, QString latitude_min) {
        qDebug() << "tabs work:" << tabName << tabTime << tabDate << tabCountry << tabProvince << tabCity << tabLongitude << tabLatitude << tabTimezone << tabUt << tabHouseSys << tabHouseSysOpt << tabLonHemi << tabLongitude_deg << tabLongitude_min << tabLatHemi << tabLatitude_deg << tabLatitude_min;
    
        ui->label_2->setText(name);
        ui->label_4->setText(time);// Set time label
        ui->label_6->setText(date);
        ui->label_8->setText(country);
        ui->label_10->setText(province);
        ui->label_12->setText(city);
        ui->label_16->setText(longitude);
        ui->label_17->setText(latitude);
        ui->label_25->setText(longitude_deg+" "+longitude_min+" "+lonhemi);
        ui->label_27->setText(latitude_deg+" "+latitude_min+" " + lathemi);
        ui->label_14->setText(timezone);
        ui->label_19->setText(ut);
        ui->label_21->setText(houseSys);
        ui->label_24->setText(houseSysOpt);
    
        ui->chartdisplay->showFile(ui->label_2->text());
        ui->widget->showFile(ui->label_2->text());
    
        tabName = name;
        tabTime = time;
        tabDate = date;
        tabCountry = country;
        tabProvince = province;
        tabCity = city;
        tabLongitude = longitude;
        tabLatitude = latitude;
        tabTimezone = timezone;
        tabUt = ut;
        tabLonHemi = lonhemi;
        tabLongitude_deg = longitude_deg;
        tabLongitude_min = longitude_min;
        tabLatHemi = lathemi;
        tabLatitude_deg = latitude_deg;
        tabLatitude_min = latitude_min;
        tabHouseSys = houseSys;
        tabHouseSysOpt = houseSysOpt;
    
        qDebug() << " name: " << name;
    
    }
    
    QString tabs::getData() {
    
        QString name = tabName;
        return name;
    
    }
    
    tabs::~tabs()
    {
        delete ui;
    }
    
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      The widget in your QMdiSubwindow is a tabs object, correct ?

      If so, you should use qobject_cast and then call the method you want on it.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2

      • Login

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