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. Return/emit/catch
Forum Updated to NodeBB v4.3 + New Features

Return/emit/catch

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 588 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
    Peter Viola
    wrote on last edited by
    #1
    //1
    class Foo : public QObject
    {
        Q_OBJECT
    public:
        explicit Foo(QObject *parent = 0) :
            m_foo(1)
        {}
        ~Foo()
        {}
    
    private:
        int m_foo;
    
    public slots:
        int divideByBar(int bar = 0)
        {
            if(bar == 0)
                return -1;
            return m_foo / bar;
        }
    };
    
    
    //"mainwindow.h"
    #include "foo.h"
    
    class MainWindow
    {
        Q_OBJECT
    public:
        MainWindow(...)
        {
            Foo *foo = new Foo(this);
            int baz = foo->divideByBar();
            if(baz == -1)
                return;
            qDebug() << "---continue---";
        }
        ~Mainwindow()
        {}
    };
    
    
    
    
    
    
    
    
    
    
    
    
    //2
    class Foo : public QObject
    {
        Q_OBJECT
        Q_PROPERTY(int foo READ foo WRITE setFoo NOTIFY fooChanged)
    public:
        explicit Foo(QObject *parent = 0) :
            m_foo(1)
        {
            connect(this, SIGNAL(fooChanged(int)), this, SLOT(setFoo(int)));
        }
        ~Foo()
        {}
    
        int foo() const;
    
    private:
        int m_foo;
    
    signals:
        void fooChanged(int foo);
    
    public slots:
        void setFoo(int foo)
        {
            setProperty("foo", foo);
        }
    
        int divideByBar(int bar = 0)
        {
            if(bar == 0)
                return -1;
            return m_foo / bar;
        }
    };
    
    //"mainwindow.h"
    #include "foo.h"
    
    class MainWindow
    {
        Q_OBJECT
    public:
        MainWindow(...)
        {
            Foo *foo = new Foo(this);
            foo->setFoo(1);
            // | foo->setProperty("foo", 1); ?
            int baz = foo->divideByBar();
            if(baz == -1)
                return;
            qDebug() << "---continue---";
        }
        ~Mainwindow()
        {}
    };
    
    
    
    
    
    
    
    
    
    
    
    
    //3
    class Foo : public QObject
    {
        Q_OBJECT
        Q_PROPERTY(int foo READ foo WRITE setFoo NOTIFY fooChanged)
    public:
        explicit Foo(QObject *parent = 0) :
            m_foo(0)
        {}
        ~Foo()
        {}
    
        int foo() const;
    
    private:
        int m_foo;
    
    signals:
        void fooChanged(int foo);
        void bazCreated(int bar);
    
    public slots:
        void setFoo(const int &foo)
        {
            if(foo == m_foo)
                return;
            m_foo = foo;
            emit fooChanged(m_foo);
        }
    
        void divideByBar(int bar = 0)
        {
            if(bar == 0)
            {
                //emit?
                emit bazCreated(-1);
                return;
            }
            //emit?
            emit bazCreated(m_foo / bar);
        }
    };
    
    //"mainwindow.h"
    #include "foo.h"
    
    class MainWindow
    {
        Q_OBJECT
    public:
        MainWindow(...)
        {
            Foo *foo = new Foo(this);
            connect(foo, SIGNAL(bazCreated(int)), this, SLOT(bazCreated(int)));
            foo->divideByBar();
        }
        ~Mainwindow()
        {}
    
    public slots:
        void bazCreated(int baz)
        {
            if(baz == -1)
                return;
    
            "---continue---";
        }
    };
    
    
    
    
    
    
    
    
    
    
    
    
    //4
    class Foo : public QObject
    {
        Q_OBJECT
        Q_PROPERTY(int foo MEMBER m_foo NOTIFY fooChanged)
    public:
        explicit Foo(QObject *parent = 0) :
            m_foo(0)
        {}
        ~Foo()
        {}
    
        int foo() const;
    
    private:
        int m_foo;
    
    public slots:
        double divideByBar(int bar = 0)
        {
            double baz = -1;
            if(bar == 0)
                throw baz;
            baz = m_foo / bar;
            return baz;
        }
    };
    
    //"mainwindow.h"
    #include "foo.h"
    
    class MainWindow
    {
        Q_OBJECT
    public:
        MainWindow(...)
        {
            Foo *foo = new Foo(this);
            try
            {
                foo->divideByBar();
            }
            catch(int baz)
            {
                "---continue---";
            }
        }
        ~Mainwindow()
        {}
    };
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      What would your question exactly be ?

      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
      3

      • Login

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