Results 1 to 14 of 14

Thread: Problem with the const

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Problem with the const

    Quote Originally Posted by aekilic View Post
    What I am doing is for a qtableview I am getting a value from 3rd row, and I send to a function in another class to calculate it. I need to send a string to calculate the value of it. In return I need this double to be on column 5th.
    Qt Code:
    1. if (index.column() == 5){
    2. calculate(index.sibling(index.row(),3).data().toString());
    3. }
    To copy to clipboard, switch view to plain text mode 
    You are discarding the return value from the function: the result won't appear anywhere.

  2. #2
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problem with the const

    this is why I forget to write

    normaly code is like this

    Qt Code:
    1. if (index.column() == 5){
    2. double d = form.calculate(index.sibling(index.row(),3).data().toString());
    3. return QString("%L1").arg((d),0,'f',2).leftJustified(true);
    4. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem with the const

    So can you paste your exact code? Because none of your snippets makes any sense. Maybe the last one is a bit more clear but still we can't deduce how form was declared and what the hell it is? :P In previous snippets you had calculate in different classes and calling it as it would be in one class... And what is:
    Qt Code:
    1. id_st=id;
    To copy to clipboard, switch view to plain text mode 
    ??
    And can you paste the exact error you get?

  4. #4
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problem with the const

    form.h
    Qt Code:
    1. class form:public QDialog, Ui::form
    2. {
    3. Q_OBJECT
    4. public:
    5. bool isUpdate;
    6. QString totaID;
    7. form(QWidget *parent = 0
    8. , const QString &uid = QString::nulll);
    9. public slots:
    10. double calculate(const QString &id);
    11. };
    12.  
    13. #endif
    To copy to clipboard, switch view to plain text mode 

    form.cpp

    Qt Code:
    1. double form::calculate(const QString &id)
    2. {
    3. totaID = id;
    4. load();
    5.  
    6. return spin->value();
    7. }
    To copy to clipboard, switch view to plain text mode 

    and after that I create a custom sqltablemodel

    Qt Code:
    1. QVariant CustomSql::data(const QModelIndex &index, int role) const
    2. {
    3. QVariant value = QSqlTableModel::data(index, role);
    4. if (value.isValid() && role == Qt::DisplayRole) {
    5. if (index.column() == 5){
    6. calculate(index.sibling(index.row(),3).data().toString());
    7. return QString("%L1").arg((d),0,'f',2).leftJustified(true);
    8. }
    9. return value.toString().leftJustified(true);
    10. }
    11. return value;
    12. }
    To copy to clipboard, switch view to plain text mode 


    am I clear?

  5. #5
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem with the const

    No, your code doesn't make any sense. You didn't show us your CustomSql::calculate() method, and d is undefined. Also load() method is not defined. And we still don't know what is the exact error you get?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem with the const

    I have a quick question for you...

    Why would you want to recalculate the value over and over again when something calls data()?

    In other words - why not calculate it once when it changes and then just return the earlier calculated value from data()?

Similar Threads

  1. Replies: 1
    Last Post: 4th December 2009, 17:03
  2. subclassed const function problem
    By qtneuling in forum Newbie
    Replies: 8
    Last Post: 22nd June 2008, 02:52
  3. const member and const method
    By mickey in forum General Programming
    Replies: 8
    Last Post: 9th April 2008, 09:44
  4. Replies: 2
    Last Post: 6th October 2006, 08:54
  5. could somebody please explain const to me?
    By mikro in forum General Programming
    Replies: 4
    Last Post: 29th September 2006, 14:34

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.