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. how to show a nomber in a message box
Forum Updated to NodeBB v4.3 + New Features

how to show a nomber in a message box

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 5 Posters 448 Views 3 Watching
  • 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.
  • A Offline
    A Offline
    arthur1000
    wrote on last edited by
    #1
    #include "MaFenetre.h"
    
    MaFenetre::MaFenetre() : QWidget()
    {
        setFixedSize(600, 300);
    
        m_lcd = new QLCDNumber(this);
        m_lcd->setSegmentStyle(QLCDNumber::Flat);
        m_lcd->setGeometry(250, 20, 100, 50);
    
        m_slider = new QSlider(Qt::Horizontal, this);
        m_slider->setGeometry(200, 100, 200, 30);
    
        m_boutonDialogue = new QPushButton("Ouvrir la boîte de dialogue", this);
        m_boutonDialogue->setGeometry(200, 150, 200, 50);
    
        QObject::connect(m_slider, SIGNAL(valueChanged(int)), m_lcd, SLOT(display(int))) ;
        QObject::connect(m_boutonDialogue, SIGNAL(clicked()), this, SLOT(ouvrirDialogue()));
    
    }
    
    void MaFenetre::ouvrirDialogue()
    {
        QMessageBox::warning(this, "Titre de la fenêtre", "here");
    }
    

    i would like to show the number on the QLCDNumber(m_lcd) in the message box
    How can i do that?

    Pl45m4P artwawA 2 Replies Last reply
    0
    • A arthur1000
      #include "MaFenetre.h"
      
      MaFenetre::MaFenetre() : QWidget()
      {
          setFixedSize(600, 300);
      
          m_lcd = new QLCDNumber(this);
          m_lcd->setSegmentStyle(QLCDNumber::Flat);
          m_lcd->setGeometry(250, 20, 100, 50);
      
          m_slider = new QSlider(Qt::Horizontal, this);
          m_slider->setGeometry(200, 100, 200, 30);
      
          m_boutonDialogue = new QPushButton("Ouvrir la boîte de dialogue", this);
          m_boutonDialogue->setGeometry(200, 150, 200, 50);
      
          QObject::connect(m_slider, SIGNAL(valueChanged(int)), m_lcd, SLOT(display(int))) ;
          QObject::connect(m_boutonDialogue, SIGNAL(clicked()), this, SLOT(ouvrirDialogue()));
      
      }
      
      void MaFenetre::ouvrirDialogue()
      {
          QMessageBox::warning(this, "Titre de la fenêtre", "here");
      }
      

      i would like to show the number on the QLCDNumber(m_lcd) in the message box
      How can i do that?

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @arthur1000

      AFAIK QMessageBox can only display text but no QWidgets.
      You can use a QDialog instead.


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      2
      • A arthur1000
        #include "MaFenetre.h"
        
        MaFenetre::MaFenetre() : QWidget()
        {
            setFixedSize(600, 300);
        
            m_lcd = new QLCDNumber(this);
            m_lcd->setSegmentStyle(QLCDNumber::Flat);
            m_lcd->setGeometry(250, 20, 100, 50);
        
            m_slider = new QSlider(Qt::Horizontal, this);
            m_slider->setGeometry(200, 100, 200, 30);
        
            m_boutonDialogue = new QPushButton("Ouvrir la boîte de dialogue", this);
            m_boutonDialogue->setGeometry(200, 150, 200, 50);
        
            QObject::connect(m_slider, SIGNAL(valueChanged(int)), m_lcd, SLOT(display(int))) ;
            QObject::connect(m_boutonDialogue, SIGNAL(clicked()), this, SLOT(ouvrirDialogue()));
        
        }
        
        void MaFenetre::ouvrirDialogue()
        {
            QMessageBox::warning(this, "Titre de la fenêtre", "here");
        }
        

        i would like to show the number on the QLCDNumber(m_lcd) in the message box
        How can i do that?

        artwawA Offline
        artwawA Offline
        artwaw
        wrote on last edited by
        #3

        @arthur1000 Hi, like @Pl45m4 said - add your own class that inherits from QDialog. You have a wizard for that too. You can customise
        it the way you like, add widgets etc.
        Functionality similar to showing the message box can be achieved using exec() method.
        Details and links to examples: https://doc.qt.io/qt-5/qdialog.html

        For more information please re-read.

        Kind Regards,
        Artur

        1 Reply Last reply
        1
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          The most simple is to use QString::arg with your QLcdNumber::value as input to build the string you pass to QMessageBox.

          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
          3
          • Ketan__Patel__0011K Offline
            Ketan__Patel__0011K Offline
            Ketan__Patel__0011
            wrote on last edited by
            #5

            Try This

            QMessageBox::information(this,"YOUR TITLE ",QString::number(m_lcd->value()));

            A 1 Reply Last reply
            2
            • Ketan__Patel__0011K Ketan__Patel__0011

              Try This

              QMessageBox::information(this,"YOUR TITLE ",QString::number(m_lcd->value()));

              A Offline
              A Offline
              arthur1000
              wrote on last edited by
              #6

              @Ketan__Patel__0011
              Thanks !!

              Ketan__Patel__0011K 1 Reply Last reply
              0
              • A arthur1000

                @Ketan__Patel__0011
                Thanks !!

                Ketan__Patel__0011K Offline
                Ketan__Patel__0011K Offline
                Ketan__Patel__0011
                wrote on last edited by
                #7

                @arthur1000

                Best of luck for you project

                if your problem is solved
                then please Mark This post as the correct answer.

                1 Reply Last reply
                1

                • Login

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