Skip to content
  • 0 Votes
    5 Posts
    8k Views
    jsulmJ

    @Tasha said in error: no match for 'operator==' (operand types are 'Visitor' and 'const QString'):

    return (firstName == firstName);

    Do you think this line makes any sense?
    This line also does not make sense:

    if(std::find(visitorsList.begin(), visitorsList.end(), visitor->getFirstName())

    You want to compare visitors, so you need a comparison function/method. You should implement this:

    bool operator==(const Visitor &otherVisitor);
  • 0 Votes
    2 Posts
    847 Views
    C

    Javascript abstracts the concept of pointers. Data is only ever passed around by reference. It is usually safer, since memory management is handled automatically and you can be sure an object equals another object if they are compared.

    If you need to compare objects to see if they are identical, you may have better luck creating a "compare" method that directly compares primitive attributes (strings can be compared directly, for instance).

    Hope this helps, sorry I can't provide a more specific implementation suggestion. Too many details to focus on at once.

  • 0 Votes
    8 Posts
    2k Views
    JKSHJ

    @oblivioncth said in Why does the const Object returned by QList::at() block access to instance methods?:

    Hey, going above and beyond! Thanks again.

    You're most welcome!

    I'm not completely ignorant in the ways of C++ though, I'm not 100% certain, but fairly confident that:

    Const 1) Ensures the returned value can't be modified,

    Yep.

    the use cases of which I'll admit I'm not really privy to.

    Use case 1:

    Allow the caller to read the data without creating a copy, AND Make sure the data is read-only

    If the returned reference is non-const, the caller will be able to directly modify the object's internal memory. This breaks encapsulation.

    Use case 2: Allow the function to be called in another const function.

    There's a const and a non-const version of QList::operator[](int):

    T & operator[](int i) const T & operator[](int i) const

    Version #1 allows the caller to modify the QList element. However, it cannot be called in a const function -- it will cause the error in your original post. Thus, version #2 is required for use in const functions.

    I know that its only really useful when dealing with user defined classes and returning by value reference (which is the case in your example) to prevent memory modification if desired.

    (Acknowledging your typo)

    Why would it be "only really useful when dealing with user defined classes"? Notice that QList::at() returns a const reference.

    I do remember seeing something about this being somewhat obsolete in C++ 11 (or was it 17) and forward, though I'm not sure why.

    Returning const references is defintiely not obsolete.

    You might be remembering move semantics, which is said to make passing parameters by const-reference obsolete: https://stackoverflow.com/questions/10231349/are-the-days-of-passing-const-stdstring-as-a-parameter-over

    Qt will not be making this change anytime soon though; this is too disruptive.

    Const 2) The pointer argument "arg" in that class is for the type "const MyOtherClass", i.e. a pointer to a constant value (value cannot)

    Yep, myfunc() cannot modify the MyOtherClass object. (In other words, it can only call const methods of the object)

    Const 3) Marks the pointer "arg" itself as pointer, so that the pointer itself also cannot be modified)

    Yep. This is not very useful IMHO, but it's part of the language.

    Const 4) Thanks to you, I now understand this means that the function does not modify the object instance that the function is being called on/from (i.e. cannot manipulate member variables).

    Great!

    Next, start thinking about the difference between logical const-ness and physical const-ness: https://isocpp.org/wiki/faq/const-correctness#logical-vs-physical-state

    Btw I do like a lot of the explanations on that site as they provide a lot of detail and examples, and I had never read the article for const.

    Agreed

  • 0 Votes
    9 Posts
    2k Views
    M

    You need to add extra logic in your prog.

    Your problem seems very similar to the Copy/Cut/Paste logic. You don't know if the paste command is valid because you don't know if the user press copy command before that.
    Well, is up to you to register the states of this commands.

    So you need to implement the logic suitable to your case, for example, if the list of items is empty, obviously you cannot edit it, etc.

    About the interfaces (as others said), create them on the fly could be tricky and error prone. You can do it if only minor changes are to be made (hide/disable a few button/options)
    If the interfaces are very different, better way to create a unique persistent widget for each, and put them in a StackedWidget.

    Good luck :;)

  • 0 Votes
    37 Posts
    5k Views
    mrjjM

    Hi
    You can use
    https://doc.qt.io/qt-5/qgraphicsitem.html#qgraphicsitem_cast
    and try cast to your child type if it really is, you can then use its members.
    so check for NULL and note the docs saying " reimplement the type() function"

  • 0 Votes
    9 Posts
    4k Views
    McLionM

    I now have an eventfilter on every of my (16) webView.
    I added some debug on the MyApp notify and in the new eventfilter.
    I can see that myApp gets every keypress (first) and the installed eventfilter on the webView's gets the keypress only if any of the webView is shown.

    I'm not sure how to proceed or how this helps in forwarding the event to a specific webView since the event is not getting to the eventfilter if a webView is not active.

    How about catching the event in MyApp notify and somehow posting it to a specific webView?

    Thanks for your help.

  • 0 Votes
    5 Posts
    2k Views
    p3c0P

    @Mathan-M Convert it to list using toList

  • 0 Votes
    2 Posts
    1k Views
    kshegunovK

    @Mark81
    Hi,

    I'm not sure if it is returned from some DBus methods or I have to manually build it using the bluetooth address and the local device.

    It is not, you have to handle it manually. From what I can discern from your link it's a path you construct out of device names. If the service is compliant you can usually list the objects it exposes.

    Kind regards.

  • 0 Votes
    4 Posts
    2k Views
    mrjjM

    Hi
    If you use layouts and put the buttons in one. Then no need
    for any code to do resize.

    So using layouts is how you do in Visual Design.

    Try this :
    Make new project
    open the mainwindow UI
    Place a button in the empty mainwindow.
    Right click empty spot on form
    Select the Layout menu (bottom)
    Select Layout Horizontally