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. The sum() action of the spreadsheet app faces problems
Forum Updated to NodeBB v4.3 + New Features

The sum() action of the spreadsheet app faces problems

Scheduled Pinned Locked Moved Unsolved General and Desktop
18 Posts 5 Posters 4.9k 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.
  • mrjjM mrjj

    @tomy said in The sum() action of the spreadsheet app faces problems:

    int i, j;
    double d;

    You do not set a initial value. (zero)

    So when you do
    d += item->text().toDouble();

    it might count funny/randomly.

    tomyT Offline
    tomyT Offline
    tomy
    wrote on last edited by tomy
    #3

    @mrjj

    int i, j;
    double d;

    You do not set a initial value. (zero)

    So when you do
    d += item->text().toDouble();

    it might count funny/randomly.

    I'd previously set them to zero but you asked me these questions:

    What happens if you select nothing and then add sum ?
    Will it not insert 0 anyway ?
    Is that how you want it?

    To be honest, through the C++ book, I've been taught that never leave a variable alone without initializing.

    I modified the code this way:

    bool b = false;
    if(!items.isEmpty()) {
           foreach (QTableWidgetItem* item, items)
               d += item->text().toDouble();
             b = true;
           }
    ...
    
    if(b)
           QTableWidget::setItem(i, j, item);
    

    Agree?

    mrjjM 1 Reply Last reply
    0
    • P Offline
      P Offline
      patrik08
      wrote on last edited by
      #4

      Why you dont use QtXlsxWriter ... this tool calculate read write excel inside all box ... e sum in easy way... this module must take a oscar...

      https://github.com/dbzhang800/QtXlsxWriter

      1 Reply Last reply
      1
      • tomyT Offline
        tomyT Offline
        tomy
        wrote on last edited by
        #5

        Thank you but I've never been in github and can't even use its contents as they are expected.

        1 Reply Last reply
        0
        • tomyT tomy

          @mrjj

          int i, j;
          double d;

          You do not set a initial value. (zero)

          So when you do
          d += item->text().toDouble();

          it might count funny/randomly.

          I'd previously set them to zero but you asked me these questions:

          What happens if you select nothing and then add sum ?
          Will it not insert 0 anyway ?
          Is that how you want it?

          To be honest, through the C++ book, I've been taught that never leave a variable alone without initializing.

          I modified the code this way:

          bool b = false;
          if(!items.isEmpty()) {
                 foreach (QTableWidgetItem* item, items)
                     d += item->text().toDouble();
                   b = true;
                 }
          ...
          
          if(b)
                 QTableWidget::setItem(i, j, item);
          

          Agree?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #6

          @tomy
          What about d ?

          tomyT 1 Reply Last reply
          0
          • mrjjM mrjj

            @tomy
            What about d ?

            tomyT Offline
            tomyT Offline
            tomy
            wrote on last edited by
            #7

            @mrjj

            What about d ?

            Hi,

            I initialized it to zero.

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

              Hi,

              What about using the debugger to get a stack trace ?

              Also, did you check the value of I ?

              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
              • tomyT Offline
                tomyT Offline
                tomy
                wrote on last edited by
                #9

                I initialized all variables to zero. It works fine now. Thanks.

                1 Reply Last reply
                0
                • tomyT Offline
                  tomyT Offline
                  tomy
                  wrote on last edited by
                  #10

                  One question on graphic visage of the app.
                  Please take a look:

                  0_1503938077733_1.png

                  To me, it looks like a Win 2000 app and old fashioned! People expect more graphical and splendid apps nowadays.
                  I think we can make such new-fashioned apps using Qt, can't we?!

                  I toyed with that and changed two lines of code from Qt_4_3 to Qt_5_9. But no influence.

                  in.setVersion(QDataStream::Qt_4_3);
                  out.setVersion(QDataStream::Qt_4_3);
                  

                  What classes or functions to use to make the app appear new and competitive from the graphics point of view, please?

                  mrjjM 1 Reply Last reply
                  0
                  • tomyT tomy

                    One question on graphic visage of the app.
                    Please take a look:

                    0_1503938077733_1.png

                    To me, it looks like a Win 2000 app and old fashioned! People expect more graphical and splendid apps nowadays.
                    I think we can make such new-fashioned apps using Qt, can't we?!

                    I toyed with that and changed two lines of code from Qt_4_3 to Qt_5_9. But no influence.

                    in.setVersion(QDataStream::Qt_4_3);
                    out.setVersion(QDataStream::Qt_4_3);
                    

                    What classes or functions to use to make the app appear new and competitive from the graphics point of view, please?

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #11

                    @tomy
                    It looks like the OS you are running on.
                    In this case windows 7.
                    It will look as win 10 when running on win 10 and so on.

                    If you want to make other type of look, you can use stylesheets or make a completly new
                    QStyle class for it. In any way, its a lot of work.

                    tomyT 1 Reply Last reply
                    1
                    • mrjjM mrjj

                      @tomy
                      It looks like the OS you are running on.
                      In this case windows 7.
                      It will look as win 10 when running on win 10 and so on.

                      If you want to make other type of look, you can use stylesheets or make a completly new
                      QStyle class for it. In any way, its a lot of work.

                      tomyT Offline
                      tomyT Offline
                      tomy
                      wrote on last edited by
                      #12

                      @mrjj

                      If you want to make other type of look, you can use stylesheets or make a completly new
                      QStyle class for it. In any way, its a lot of work.

                      Do you think it's because of the old-fashioned book I use (C++-GUI-Programming-with-Qt-4-2ndEdition) or the look is the basic and I will use the new ones when I get further in the book?

                      mrjjM 1 Reply Last reply
                      0
                      • tomyT tomy

                        @mrjj

                        If you want to make other type of look, you can use stylesheets or make a completly new
                        QStyle class for it. In any way, its a lot of work.

                        Do you think it's because of the old-fashioned book I use (C++-GUI-Programming-with-Qt-4-2ndEdition) or the look is the basic and I will use the new ones when I get further in the book?

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #13

                        @tomy
                        Nope, its not related to the age of the book and it will look the same also later on.
                        Its how widget application looks. unless you make your own style.
                        It looks like all the other win 7 apps which is by design.

                        tomyT 1 Reply Last reply
                        2
                        • mrjjM mrjj

                          @tomy
                          Nope, its not related to the age of the book and it will look the same also later on.
                          Its how widget application looks. unless you make your own style.
                          It looks like all the other win 7 apps which is by design.

                          tomyT Offline
                          tomyT Offline
                          tomy
                          wrote on last edited by
                          #14

                          @mrjj

                          Its how widget application looks. unless you make your own style.

                          What do you mean by that, please? do you mean I use some other classes for my app?
                          What minor changes I can do to my app to look a little nicer?

                          It looks like all the other win 7 apps which is by design.

                          Hmm, but my prior app (Calculator) looks more graphical and resembles nowadays Wind 7/10 app!

                          jsulmJ 1 Reply Last reply
                          0
                          • tomyT tomy

                            @mrjj

                            Its how widget application looks. unless you make your own style.

                            What do you mean by that, please? do you mean I use some other classes for my app?
                            What minor changes I can do to my app to look a little nicer?

                            It looks like all the other win 7 apps which is by design.

                            Hmm, but my prior app (Calculator) looks more graphical and resembles nowadays Wind 7/10 app!

                            jsulmJ Offline
                            jsulmJ Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on last edited by
                            #15

                            @tomy A Qt app usually looks like any other app on the system where it is executed. On Windows 7 it looks like Windows 7 applications, on Windows 10 it looks like a Windows 10 application. Not sure why you bother about this while reading the book.
                            If you want your app to look differently then you can use stylesheets: http://doc.qt.io/qt-4.8/stylesheet-examples.html

                            https://forum.qt.io/topic/113070/qt-code-of-conduct

                            mrjjM 1 Reply Last reply
                            2
                            • jsulmJ jsulm

                              @tomy A Qt app usually looks like any other app on the system where it is executed. On Windows 7 it looks like Windows 7 applications, on Windows 10 it looks like a Windows 10 application. Not sure why you bother about this while reading the book.
                              If you want your app to look differently then you can use stylesheets: http://doc.qt.io/qt-4.8/stylesheet-examples.html

                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #16
                              • What minor changes I can do to my app to look a little nicer?
                                what would make it look nicer?
                                You can use other icons or colors but overall it will still look like the platform.
                              tomyT 1 Reply Last reply
                              1
                              • mrjjM mrjj
                                • What minor changes I can do to my app to look a little nicer?
                                  what would make it look nicer?
                                  You can use other icons or colors but overall it will still look like the platform.
                                tomyT Offline
                                tomyT Offline
                                tomy
                                wrote on last edited by
                                #17

                                @mrjj
                                So the only solution is http://doc.qt.io/qt-4.8/stylesheet-examples.html although I don't know where in the app (the screen, buttons, tables etc), it changes and still needs a lot of work.

                                Okey. Thank you.

                                mrjjM 1 Reply Last reply
                                0
                                • tomyT tomy

                                  @mrjj
                                  So the only solution is http://doc.qt.io/qt-4.8/stylesheet-examples.html although I don't know where in the app (the screen, buttons, tables etc), it changes and still needs a lot of work.

                                  Okey. Thank you.

                                  mrjjM Offline
                                  mrjjM Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #18

                                  @tomy
                                  Yes its lots of work to make new look.

                                  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