Skip to content
QtWS25 Call for Papers
  • 0 Votes
    30 Posts
    982 Views
    S

    @SGaist I actually have some of them built already. Thats why i was asking what would be better/ if my approach with the database would be viable. :)
    Have a nice easter.

  • 0 Votes
    2 Posts
    200 Views
    T

    Your code should be fine. I think that the console.log() command is just in the wrong place.

    If I understood correctly, there are two user interactions involved. The first one is the click on the mouse area, which opens the menu. The second one is a click on a particular menu item, which actually sets the test value.

    Let's say you are performing the first interaction for the first time. At this point, the variable hasn't been set as you haven't clicked on a menu item yet. That is why the output of the console.log() command will be undefined. Then, you click on a menu item, which sets the variable. However, you won't be able to see the change until the menu is closed and you perform another click on the mouse area to make the menu pop up again.

    I think you'll see that your code works if you move the console.log() command to a different place:

    id: mouseArea1 property var testValue; onClicked: { menu.popup(); } Menu { id: menu MenuItem { text: "Option1" onTriggered: { mouseArea1.testValue= "25"; console.log(mouseArea1.testValue); } } }

    I don't know how many menu items you have in your actual code. Doing it this way, you'd need to add the same line to the onTriggered() signal handlers on all MenuItem instances, which could be annoying and bloat your code unnecessarily. So I'd suggest doing this instead:

    id: mouseArea1 property var testValue; onClicked: { menu.popup(); } Menu { id: menu MenuItem { text: "Option1" onTriggered: { mouseArea1.testValue= "25"; } } onClosed: { console.log(mouseArea1.testValue); } }

    I am assuming that the menu is closed once you hit a menu item. The code above logs the variable once the menu emits a closed() signal. I haven't tried it myself, but it should work. :)

  • 0 Votes
    7 Posts
    666 Views
    SGaistS

    Hi and welcome to devnet,

    From the looks of it, you are likely accessing the QPushButton directly from your custom thread which is forbidden. GUI element manipulation shall happen in the main thread.

  • 0 Votes
    7 Posts
    767 Views
    fcarneyF

    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.

  • 0 Votes
    4 Posts
    997 Views
    Christian EhrlicherC

    You already use QTextStream::readLine() - so why do you read it with ifstream before? You simply read it twice for no reason.

  • 0 Votes
    4 Posts
    997 Views
    A

    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

  • 0 Votes
    3 Posts
    4k Views
    jsulmJ

    @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.

  • 0 Votes
    5 Posts
    2k Views
    p3c0P

    @Mathan-M Convert it to list using toList

  • 0 Votes
    11 Posts
    2k Views
    SGaistS

    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.

  • 0 Votes
    2 Posts
    1k Views
    SGaistS

    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.

  • 0 Votes
    2 Posts
    706 Views
    mrjjM

    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
    }

  • 0 Votes
    3 Posts
    1k Views
    cxamC

    @mrjj Thanks Mrjj :) it went perfect, you're awesome haha ;)

  • 0 Votes
    2 Posts
    2k Views
    M

    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

  • 0 Votes
    4 Posts
    1k Views
    S

    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 ;)

  • 0 Votes
    2 Posts
    2k Views
    A

    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 .