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. About functions and lineEdit
Forum Updated to NodeBB v4.3 + New Features

About functions and lineEdit

Scheduled Pinned Locked Moved General and Desktop
25 Posts 3 Posters 6.9k 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.
  • P Offline
    P Offline
    Project try
    wrote on 6 Mar 2014, 22:42 last edited by
    #12

    Same error man :( , even when I write the first two or three letters the function doesn't show , other functions shows like setlocal

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 6 Mar 2014, 22:53 last edited by
      #13

      Can you show the code where this setLayout can be found ?

      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
      0
      • P Offline
        P Offline
        Project try
        wrote on 6 Mar 2014, 22:57 last edited by
        #14

        @
        #include <QApplication>
        #include<QLabel>
        #include<QHBoxLayout>
        #include<QLineEdit>
        #include<QIntValidator>
        #include <QWidget>

        int sum(int x,int y){
        return x+y;
        }

        int main(int argc, char *argv[])
        {
        int x;
        int y;
        QApplication a(argc, argv);

        QLabel *check=new QLabel(QObject::tr("Add numbers:"));
        
        QHBoxLayout *left=new QHBoxLayout;
        
        left->addWidget(check);
         QValidator *Valid=new QIntValidator();
        
        QLineEdit *edit =new QLineEdit;
        edit->setMaximumWidth(5);
        edit->setFixedWidth(5);
        check->setBuddy(edit);
        edit->setValidator(Valid);
        QObject::connect(edit,SIGNAL(editingFinished()),edit,SLOT(setText(x)));
        QLineEdit *edit1=new QLineEdit;
        edit1->setMaximumWidth(5);
        edit1->setFixedWidth(5);
        check->setBuddy(edit1);
        edit1->setValidator(Valid);
        QObject::connect(edit1,SIGNAL(editingFinished()),edit1,SLOT(setText(y)));
                left->addWidget(edit);
        QHBoxLayout *Mainlayout=new QHBoxLayout;
        Mainlayout->addLayout(left);
        

        setLayout(Mainlayout);

        sum(x,y);

        return a.exec&#40;&#41;;
        

        }

        @

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 6 Mar 2014, 23:07 last edited by
          #15

          That won't do what you want at all.

          You are calling setLayout in main and not on a widget

          Also your connection statements are wrong.

          Please, have a look at some of Qt's example to see how things work

          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
          0
          • P Offline
            P Offline
            Project try
            wrote on 6 Mar 2014, 23:11 last edited by
            #16

            Well , that's the only way I would learn is by making mistakes :D , that's why I wanted to do it my way before trying what you guys have told me.

            by the way why can't I call it in main ? should I include something first ?

            1 Reply Last reply
            0
            • P Offline
              P Offline
              Project try
              wrote on 6 Mar 2014, 23:13 last edited by
              #17

              and could you please tell me where should I call it ?

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 6 Mar 2014, 23:17 last edited by
                #18

                setLayout is a function of QWidget, so you need a QWidget object.

                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
                0
                • P Offline
                  P Offline
                  Project try
                  wrote on 6 Mar 2014, 23:18 last edited by
                  #19

                  what if I made a class and inherited qwidget ? or there's a better way ?

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    Project try
                    wrote on 6 Mar 2014, 23:21 last edited by
                    #20

                    Oh , so I could just create a pointer to that object and use that pointer to set the layout ? and if I wanted to make bigger programs I should just inherit it on my classes ?

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 6 Mar 2014, 23:22 last edited by
                      #21

                      Subclass QWidget, it's the correct way to go here.

                      You really should take a look at Qt's demos and examples, that will give you a good ground to build on

                      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
                      0
                      • P Offline
                        P Offline
                        Project try
                        wrote on 6 Mar 2014, 23:26 last edited by
                        #22

                        I really looked at some examples about two weeks ago " I don't have much time " since I've been busy with my midterms exams :(

                        but I'll finish this one , hopefully it will work then I'll look at some examples tomorrow.

                        1 Reply Last reply
                        0
                        • P Offline
                          P Offline
                          Project try
                          wrote on 6 Mar 2014, 23:27 last edited by
                          #23

                          about converting from string to int , should always do this ? is there a way to just take an integer or any type i want from the user ?

                          1 Reply Last reply
                          0
                          • P Offline
                            P Offline
                            Project try
                            wrote on 7 Mar 2014, 00:11 last edited by
                            #24

                            I think I'll create a new class to do these things , specially that this won't work because there's no reference. is it ok if I posted on this thread tomorrow ? or it's against the rules to bump a thread with +12 hours without posting ?

                            thanks man , I really appreciate your help.

                            1 Reply Last reply
                            0
                            • S Offline
                              S Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on 7 Mar 2014, 08:16 last edited by
                              #25

                              It's better not to bump 24 hours is the common time interval.

                              If you want integers directly, use a QSpinBox, it will simplify your program

                              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
                              0

                              21/25

                              6 Mar 2014, 23:22

                              • Login

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