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. Passing QString to function.
Forum Updated to NodeBB v4.3 + New Features

Passing QString to function.

Scheduled Pinned Locked Moved Solved General and Desktop
18 Posts 5 Posters 5.6k 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #6

    Hi,

    It should rather be:

    QGroupBox *EyeCare::createBrightnessSettings(const QString &name) //<< const reference as @koahnig suggested
    {
    
        QGroupBox *brightnessSettings = new QGroupBox(name);
        ...
    }
    ...
    layout->addWidget(createBrightnessSettings(tr("Brightness Settings")),0,0,Qt::AlignLeft); // the tr methods are usually put around text that you want to mark for translation.
    ...
    

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

    AhtiA 1 Reply Last reply
    2
    • SGaistS SGaist

      Hi,

      It should rather be:

      QGroupBox *EyeCare::createBrightnessSettings(const QString &name) //<< const reference as @koahnig suggested
      {
      
          QGroupBox *brightnessSettings = new QGroupBox(name);
          ...
      }
      ...
      layout->addWidget(createBrightnessSettings(tr("Brightness Settings")),0,0,Qt::AlignLeft); // the tr methods are usually put around text that you want to mark for translation.
      ...
      
      AhtiA Offline
      AhtiA Offline
      Ahti
      wrote on last edited by
      #7

      @SGaist Still not working man
      throwing error "program has unexpectedly finished"
      and when i debug after a while it shows something wrong on this line :

      QGroupBox *brightnessSettings = new QGroupBox(name);
      

      thanks

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

        What does the stack trace tells you ?

        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
        • hskoglundH Online
          hskoglundH Online
          hskoglund
          wrote on last edited by
          #9

          Hi, also you could try (this is just a guess) to go via a normal QString, like this:

          {
              QString name2(name);
              QGroupBox *brightnessSettings = new QGroupBox(name2);
              ...
          }
          
          AhtiA 1 Reply Last reply
          0
          • hskoglundH hskoglund

            Hi, also you could try (this is just a guess) to go via a normal QString, like this:

            {
                QString name2(name);
                QGroupBox *brightnessSettings = new QGroupBox(name2);
                ...
            }
            
            AhtiA Offline
            AhtiA Offline
            Ahti
            wrote on last edited by Ahti
            #10

            @SGaist @hskoglund @Eddy

            here have a look of debug result:
            https://postimg.org/image/6g1fp20zb/

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

              Something fishy: settingsBackground = constructFrame(this, settingsBackground, 10, 145, 640, 320);

              Frankly the code itself looks like its doing pretty strange thing to setup the widget.

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

              AhtiA 1 Reply Last reply
              1
              • SGaistS SGaist

                Something fishy: settingsBackground = constructFrame(this, settingsBackground, 10, 145, 640, 320);

                Frankly the code itself looks like its doing pretty strange thing to setup the widget.

                AhtiA Offline
                AhtiA Offline
                Ahti
                wrote on last edited by Ahti
                #12

                @SGaist

                I don't think anything is fishy with constructFrame(); why would you think that ?

                constructFrame definition:

                QFrame* EyeCare::constructFrame(QWidget *parent, QFrame *frameName,
                                             int x, int y, int w, int h, QString style) {
                
                    frameName = new QFrame(parent) ;
                    frameName->setGeometry(x,y,w,h);
                    if (!style.isEmpty())
                        frameName->setStyleSheet(style);
                    return frameName ;
                }
                

                I don't think there is anything wrong with it because i am using it with other places in my code and i have no issue with it.

                What you think is strange please be specific ?

                btw this is what i am trying to achieve with the code :

                https://postimg.org/image/i30xl23g5/

                1 Reply Last reply
                0
                • AhtiA Ahti

                  @SGaist @hskoglund @Eddy

                  here have a look of debug result:
                  https://postimg.org/image/6g1fp20zb/

                  hskoglundH Online
                  hskoglundH Online
                  hskoglund
                  wrote on last edited by
                  #13

                  @Ahti Hi, looking at https://postimg.org/image/6g1fp20zb/ it seems that inside createBrightnessSettings you call createBrightnessSettings 2 times (one for "Day Mode" and one for "Night Mode") so that first time there are 2 calls, then 4, then 8, then 16 etc.... When recursive-calling yourself you need some mechanism to stop otherwise the program will crash :-(

                  AhtiA 1 Reply Last reply
                  2
                  • hskoglundH hskoglund

                    @Ahti Hi, looking at https://postimg.org/image/6g1fp20zb/ it seems that inside createBrightnessSettings you call createBrightnessSettings 2 times (one for "Day Mode" and one for "Night Mode") so that first time there are 2 calls, then 4, then 8, then 16 etc.... When recursive-calling yourself you need some mechanism to stop otherwise the program will crash :-(

                    AhtiA Offline
                    AhtiA Offline
                    Ahti
                    wrote on last edited by
                    #14

                    @hskoglund but at the end it has a return statement which would return the "brightnessSettings" QGroupBox pointer this is where stopping mechanism for recursive call happens returning from every call would ultimately bring it out of the createBrightnessSettings() function .

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

                      Then why pass frameName as argument to that function ?

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

                      AhtiA 2 Replies Last reply
                      1
                      • SGaistS SGaist

                        Then why pass frameName as argument to that function ?

                        AhtiA Offline
                        AhtiA Offline
                        Ahti
                        wrote on last edited by Ahti
                        #16

                        @SGaist I am creating more than one frame that is why i have to pass the name of the frame that i want to create.

                        like for example :

                        homeBackground = constructFrame(this,homeBackground,10,145,640,320) ;
                        settingsBackground = constructFrame(this,settingsBackground,10,145,640,320) ;
                        topSeperator = constructFrame(contactBackground,topSeperator,5,60,635,2,"background-color:white;") ;
                        ...
                        
                        1 Reply Last reply
                        0
                        • SGaistS SGaist

                          Then why pass frameName as argument to that function ?

                          AhtiA Offline
                          AhtiA Offline
                          Ahti
                          wrote on last edited by
                          #17
                          This post is deleted!
                          1 Reply Last reply
                          0
                          • AhtiA Ahti

                            @hskoglund but at the end it has a return statement which would return the "brightnessSettings" QGroupBox pointer this is where stopping mechanism for recursive call happens returning from every call would ultimately bring it out of the createBrightnessSettings() function .

                            hskoglundH Online
                            hskoglundH Online
                            hskoglund
                            wrote on last edited by
                            #18

                            @Ahti well the recursiveness is still fatal, createBrightnessSettings("Night Mode",...) is never reached, instead createBrightnessSettings("Day Mode"... is calling itself many millions of times then the app crashes because of stack overflow.

                            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