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. Calling text() after the connect
Forum Updated to NodeBB v4.3 + New Features

Calling text() after the connect

Scheduled Pinned Locked Moved General and Desktop
10 Posts 2 Posters 2.7k Views 1 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.
  • T Offline
    T Offline
    tecky
    wrote on last edited by
    #1

    i post it 2nd time, coz everybody try to help me and just indicate a problem, but i cant solve it by myself =(
    main only:
    @

    QApplication a(argc, argv);
    QWidget w;
    QComboBox* cmb = new QComboBox;
    QPushButton* btn = new QPushButton("add");
    QDial* dial = new QDial;
    QLabel* lbl = new QLabel(" ");

    cmb->addItem("item1");
    cmb->addItem("dial");
    cmb->addItem("item3");
    

    dial->hide();

    if (lbl->text() == "dial") {
    QObject::connect(btn, SIGNAL(clicked()),
    dial, SLOT (show())
    );
    }
    QObject::connect(cmb, SIGNAL(currentTextChanged(QString)),
    lbl, SLOT (setText(QString))
    );
    @
    i can change lbl for "item1", "dial", "item3", but lbl->text is always item1.
    calling text() after the connect will of course give you the text of the first item, because it is executed before you change the selection in the GUI.
    ok. but how can i solve it. just write specific lines. ty

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      Hi,

      simply you can't do it without writing a cusom SLOT.
      You musy write your QWidget subclass and connect the currentTextChanged signal to a custom slot like this

      @
      void MyWidget::mySlot (QString _text)
      {
      lbl->setText(_text);
      if (_text == "dial")
      QObject::connect(btn, SIGNAL(clicked()), dial, SLOT (show()));

      }
      @

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tecky
        wrote on last edited by
        #3

        i have no expiriance in it...
        correct it plz:
        .h
        @

        class MyWidget : public QObject
        {
        Q_OBJECT
        private:
        QString _text;
        public:
        MyWidget();
        public slots:
        void MySlot(QString _text);

        };
        @

        .cpp:
        @
        MyWidget::MyWidget() :
        QObject()
        ,_text

        {

        }

        void MyWidget::mySlot(QString _text)
        {
        lbl->setText(_text);
        if (_text == "dial")
        QObject::connect(btn, SIGNAL(clicked()),
        dial, SLOT (show()));

        }
        @

        main is ok now

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mcosta
          wrote on last edited by
          #4

          Hi,

          I'd like to help you but I think you MUST study a little bit more about Qt before to ask some kind of help.
          What you're asking isn't to help you but to write code for you. If we do this, you don't learn anything.

          I hope you understand why I do this.

          Once your problem is solved don't forget to:

          • Mark the thread as SOLVED using the Topic Tool menu
          • Vote up the answer(s) that helped you to solve the issue

          You can embed images using (http://imgur.com/) or (http://postimage.org/)

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tecky
            wrote on last edited by
            #5

            ok i will
            ty for tolerance
            i try to do my best

            1 Reply Last reply
            0
            • T Offline
              T Offline
              tecky
              wrote on last edited by
              #6

              but its dificult to learn it w/o communication.
              i have lot of questions. there are no answers in books((

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mcosta
                wrote on last edited by
                #7

                Hi,

                obviously you can ask, I only suggested to study a litte bit before to post questions.

                Sometime is faster read a manual/documentatios than post a question and wait for an aswer

                Once your problem is solved don't forget to:

                • Mark the thread as SOLVED using the Topic Tool menu
                • Vote up the answer(s) that helped you to solve the issue

                You can embed images using (http://imgur.com/) or (http://postimage.org/)

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  tecky
                  wrote on last edited by
                  #8

                  mcosta,
                  may be its willfully, boldly and foolishly a little, but i still need answer ( i rly need this, * just this* lines) in my .h and .cpp files
                  can u allocate 10 mins for me and i will back to my book
                  (sry for my english too)

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mcosta
                    wrote on last edited by
                    #9

                    Hi,

                    this is a code example

                    MyWidget.h
                    @
                    #ifndef MYWIDGET_H
                    #define MYWIDGET_H

                    #include <QWidget>

                    class MyWidget: public QWidget
                    {
                    Q_OBJECT

                    public:
                    MyWidget (QWidget* _parent = 0);

                    private slots:
                    void mySlot (QString _text);

                    private:
                    QComboBox *cmb;
                    .....
                    };
                    #endif // MYWIDGET_H
                    @

                    MyWidget.cpp
                    @
                    #include "MyWidget.h"

                    MyWidget::MyWidget (QWidget* _parent): QWidget (_parent)
                    {
                    cmb = new QComboBox (this);
                    ...

                    connect(cmb, SIGNAL(currentTextChanged(QString)),
                    this, SLOT (mySlot(QString))
                    }

                    void MyWidget::mySlot(QString _text)
                    {
                    lbl->setText (_text);
                    if (_text == "dial")
                    connect(btn, SIGNAL(clicked()), dial, SLOT (show()));
                    }
                    @

                    Once your problem is solved don't forget to:

                    • Mark the thread as SOLVED using the Topic Tool menu
                    • Vote up the answer(s) that helped you to solve the issue

                    You can embed images using (http://imgur.com/) or (http://postimage.org/)

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      tecky
                      wrote on last edited by
                      #10

                      Thank you for everything. I appreciate this

                      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