Results 1 to 6 of 6

Thread: Qt Script

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2016
    Posts
    3

    Default Re: Qt Script

    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6.  
    7. a = new Cross();
    8. b = new Cross();
    9.  
    10. a->CrossOver(10, 20);
    11. b->CrossOver(11, 22);
    12. }
    To copy to clipboard, switch view to plain text mode 

    This would be evaluation
    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3. a->CrossOver(30, 19);
    4. b->CrossOver(20, 22);
    5. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #ifndef CROSS_H
    2. #define CROSS_H
    3.  
    4. #include <QDebug>
    5. #include <QObject>
    6.  
    7. class Cross : public QObject
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. Cross();
    13. bool CrossOver(int a, int b);
    14.  
    15. signals:
    16.  
    17. public slots:
    18.  
    19. private:
    20. int prevA;
    21. int prevB;
    22. };
    23.  
    24. #endif // CROSS_H
    To copy to clipboard, switch view to plain text mode 

    // .cpp
    Qt Code:
    1. Cross::Cross()
    2. {
    3. prevA = 0;
    4. prevB = 0;
    5. }
    6.  
    7. bool Cross::CrossOver(int a, int b)
    8. {
    9. bool ret = false;
    10.  
    11. qDebug() << "a " << a;
    12. qDebug() << "b " << b;
    13. qDebug() << "prevA " << prevA;
    14. qDebug() << "prevB " << prevB;
    15.  
    16. if(a > b && prevA < prevB)
    17. ret = true;
    18.  
    19. prevA = a;
    20. prevB = b;
    21.  
    22. qDebug() << "Result is " << ret;
    23. qDebug() << "";
    24.  
    25. return ret;
    26. }
    To copy to clipboard, switch view to plain text mode 

    I don't know how to make this for qscript.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Qt Script

    Ok, this makes this even more difficult to understand.

    Now you have two objects of your Cross class?

    And your script also needs two?

    So that you get two pairs of prevA/prevB value?

    Cheers,
    _

  3. #3
    Join Date
    Jul 2016
    Posts
    3

    Default Re: Qt Script

    I don't know how to explain it better, the task is simple.
    User write script i have to run it every few seconds.
    He can write

    bool res1 = cross(x, y);
    bool res2 = cross(c, d);
    etc..
    as many times he want, and i need to do math behind it. Now each function of cross have to store previous values, as this is how cross is calculated. It's like this script will run in loop.
    Now if user could write only one cross, i would simply store as static previous values inside cross function. But there can be multiple of them.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Qt Script

    From your original post and the comment #5 I would have guessed that the second call to cross() sees the values of the first call as prevA and prevB.
    But then you posted comment #3 and make the two calls on separate objects.

    So maybe instead of writing code that doesn't do what you need it to do, you could give an example with actual values for a, b, prevA and prevB?

    Cheers,
    _

Similar Threads

  1. Qt script combined with java script
    By prachi kamble in forum Newbie
    Replies: 8
    Last Post: 16th April 2015, 13:30
  2. Qml non Gui script
    By codeman in forum Qt Quick
    Replies: 7
    Last Post: 21st July 2014, 11:32
  3. Using QT Script...
    By minhaz in forum Newbie
    Replies: 1
    Last Post: 18th August 2009, 22:29
  4. Can I include a script from script?
    By yycking in forum Qt Programming
    Replies: 1
    Last Post: 24th April 2009, 03:01
  5. Qt script
    By rajesh_clt3 in forum Qt Programming
    Replies: 2
    Last Post: 27th July 2007, 12:40

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.