Navigation

    Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Search
    1. Home
    2. Tags
    3. variable
    Log in to post

    • UNSOLVED C++ to QML: many variable to exchange - Best solution
      QML and Qt Quick • qml c++ variable backend data transfer • • TMJJ001  

      7
      0
      Votes
      7
      Posts
      82
      Views

      You could create a standardized set of mule objects based upon QObject that handle signals of different data types. Then add the appropriate ones to the classes that need them as members or inherit them. Create callbacks that are called by these mule objects with the behavior needed from each class or other structure. If you don't inherit from them you can still use templates on the objects that own the QObjects if you need to simply other boiler plate code. I needed the opposite the other day. I had templated classes I wanted to add signals to. So I created a data member mule QObject. Edit: One problem with this approach is that object properties would not be unique. Not sure how to get around that.
    • UNSOLVED how to split a string and set as variable then show in plaintext editor?
      General and Desktop • qt5 string search variable setplaintext • • vehicular  

      4
      0
      Votes
      4
      Posts
      279
      Views

      You already use QTextStream::readLine() - so why do you read it with ifstream before? You simply read it twice for no reason.
    • UNSOLVED how to add a variable in an other variables name?
      General and Desktop • c++ problem variable name add • • GhostWolf  

      4
      0
      Votes
      4
      Posts
      535
      Views

      Fill all results of checked check boxes into a list, and then take the first n entries from that list (up to the number you need, or the size of the list) EDIT: If you put the checkboxes into a container, you just have to loop over it
    • SOLVED sending variables dynamically using signals and slots
      General and Desktop • qtcreator dynamic signals&slots variable • • Lasith  

      3
      0
      Votes
      3
      Posts
      2404
      Views

      @Lasith Well, emit a signal, pass the current value to it as parameter. Connect the signal to the slot. // somewhere in your code connect(this, SIGNAL(mySignal(int)), otherObject, SLOT(mySlot(int))); for (int i = 0; i < 10; ++i) { emit mySignal(i); } // In the other class void MyObject::mySlot(const int value) { // Do something } Did you read http://doc.qt.io/qt-5.9/signalsandslots.html ? Actually you should think about the need of signals and slots in this particular case - maybe it will be much easier and faster to directly call a method from the other class instead of emitting a signal? Signals/slots are useful if you want to have loose coupling, so the sender does not need to know anything about receiver.
    • UNSOLVED How to pass the javascript var from qml to CPP?
      General and Desktop • qml variable object javascript qml • • Mathan M  

      5
      0
      Votes
      5
      Posts
      1254
      Views

      @Mathan-M Convert it to list using toList
    • UNSOLVED Using the same variable (and its value) in different classes
      General and Desktop • class variable • • gabor53  

      11
      0
      Votes
      11
      Posts
      1828
      Views

      AFAIU, these are not really errors in the sense of validation. Your user forgot to e.g. check an option in a multiple choice question but that doesn't count as "wrong" like he tried to put an invalid value. Thus I don't see the need to modify Additem back from Review.
    • UNSOLVED Class variable updating / QLabel | Thread
      General and Desktop • qlabel class variable updat • • paul_b  

      2
      0
      Votes
      2
      Posts
      888
      Views

      Hi and welcome to devnet, What variable do you want to update ? Why do you think you need a thread for that ? On a side note, update is a QWidget non virtual slot so you can't use that name. In any case you should call labelTimr->setText("TIME :" + timeValue) to update the content of your QLabel.
    • UNSOLVED Using variables to acces UI
      General and Desktop • variable ui object • • plymouth21  

      2
      0
      Votes
      2
      Posts
      526
      Views

      Hi and welcome There is a special sender() in a slot you can use to know which button was the sender of the clicked() signal void aaa::on_push_button1_clicked() QPushButton *butt=qobject_cast<QPushButton *> ( sender() ) ; if (butt) { } that way u can use a variable and not ui->NAME All you buttons should be connected to same slot then. You could do that after setupUI() QList<QPushButton *> list = this->findChildren<QPushButton *>(); foreach(QPushButton *b, list) { connect(b, XXX }
    • SOLVED TextChanged variable unreachable ?
      General and Desktop • qstring qlineedit variable qlinedit • • cxam  

      3
      0
      Votes
      3
      Posts
      907
      Views

      @mrjj Thanks Mrjj :) it went perfect, you're awesome haha ;)
    • UNSOLVED Qt5 QSqlDatabase: read PL/SQL variable from oracle
      General and Desktop • sql qsqldatabase variable oracle • • Hans Hupe  

      2
      0
      Votes
      2
      Posts
      1613
      Views

      I'm not familiar with Oracle, but this looks close enough to Postgresql that I'll show how I would do it in PG/SQL in hopes that it will be useful. I would create the function in the database CREATE OR REPLACE FUNCTIOM test_fucntion(_name TEXT) RETURNS BIGINT AS $BODY$ DECLARE _rv BIGINT BEGIN INSERT INTO test_table(name) VALUES(_name) RETURNING id into _rv; RETURN _rv; END; $BODY$ LANGUAGE plpgsql; After adding that function to the database you can simply execute the query SELECT * from test_function("name"); to get your ID. As I said, this is Postgres code, but I'm pretty sure the Postgres authors imitated Oracle to some extent. Mike
    • [solved] access data globally within application
      General and Desktop • variable global • • sachi  

      4
      0
      Votes
      4
      Posts
      973
      Views

      The singleton is part of the software design patterns. The implementation is easy: make the ctor private and implement one public static function which creates the instance: class Foo { private: static Foo* _instance; Test(); public: static Foo* getInstance() { if (_instance==NULL) _instance = new Foo(); return _instance; } cpp: Foo::_instance = NULL; And, please, put not all 'global variables' into one place, but consider the SOLID principles ;)
    • Can't declare QPixmap as global variable
      General and Desktop • qpixmap variable global • • Rphysx  

      2
      0
      Votes
      2
      Posts
      1491
      Views

      This seems a misunderstanding of language basics. Global and extern meaning are different. I would highly advice reading the book. But briefly: In such context extern means that you want to access variable _corner which is declared and instantiated in other module. Since it is not true you get a link error. At the same time I would highly advice against global variables in C++. Using such leads to code which is highly difficult to maintain. If you really need something accessible globally you may either subclass QApplication or use singleton pattern or at least use static class members .