Skip to content
  • 0 Votes
    4 Posts
    194 Views
    ekkescornerE

    instead of setContextProperty() you should use QML_SINGLETON
    see: https://t1p.de/ekkeQML_SINGLETON

  • 0 Votes
    5 Posts
    1k Views
    W

    @Ronel_qtmaster
    oh i understood what i wasn't getting yeah idk why i did that, thanks!
    onto the next mistake....

  • 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
    5 Posts
    803 Views
    mrjjM

    Hi
    You always have to initialize a pointer.
    Else it will crash on use.
    Hint:
    There is only one constructor and it takes a parameter :)

  • 0 Votes
    16 Posts
    1k Views
    jsulmJ

    @HenrikSt-0 said in Starting App from other class:

    GraphDataGenerator

    It is the class in the example - did you add it to your project?

  • 0 Votes
    9 Posts
    915 Views
    mrjjM

    @JonnyQB
    Hi
    You declare it like
    Punkte * punkten;

    Then some place else you must do
    punkten = new Punkte(); ( not in .h)
    Often the constructor is a good place.

  • 0 Votes
    4 Posts
    886 Views
    F

    The problem was that my class inherited QGraphicsItem, not QObject, but I found another way to do what I wanted. From now on, I will use the new syntax. Thank you!

  • 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
    22 Posts
    14k Views
    A

    @Nico1564 said in How to draw on Image loaded in a QGraphicsView:

    Yeah i know that this work but i need to draw with fonctions. I successed to do that but I don't want to have the GraphicsView at the beginning of the program, and i want to add draws like an Ellipse (and the image) when i click on buttons.

    These lines could just as well happen inside a button click

    QGraphicsEllipseItem* testItem = new QGraphicsEllipseItem(20,30,120,70,0); m_pScene->addItem(testItem);

    In that case, you would create an ellipse every time you pressed that button.

    I don't quite understand the "I don't want to have the GraphicsView at the beginning of the program" - maybe you could elaborate on that.

  • 0 Votes
    7 Posts
    2k Views
    VRoninV

    change progsettings result = Data.Process(); to auto result = Data.Process();

    I'm trying to get the 2D array of QString.

    change:

    QString progsettings[50][2]; to std::array<std::array<QString,2>,50> progsettings; (you need #include <array>) QString Process(); to const std::array<std::array<QString,2>,50>& Process(); QString ReadProgData::Process() to const std::array<std::array<QString,2>,50>& ReadProgData::Process()
  • 0 Votes
    7 Posts
    2k Views
    Pradeep KumarP

    @Kalado said in Connect() uses wrong emitter object.:

    Look at some code:

    //A.h class task2 : public QWidget { Q_OBJECT public: task2(QWidget *parent = 0); ~task2(); protected: void mousePressEvent(QMouseEvent *event) override; signals: void myWidgetClicked(); //A.cpp void A::mousePressEvent(QMouseEvent *event){ /// use the respective classname emit myWidgetClicked(); }

    If ur using Classname as task2 , use

    void task2::mousePressEvent(QMouseEvent *event){ emit myWidgetClicked(); }

    Thanks,

  • 0 Votes
    11 Posts
    8k Views
    D

    @yuvaram

    If so, compile it with Network Download Example, which is officially available from Qt.

  • 0 Votes
    4 Posts
    6k Views
    oblivioncthO

    @Wieland Wow you are just killing it today for me aren't you? Haha. I'll judge which is best for me a give it a roll.

    Thanks a bunch (again)!

    EDIT:

    I ended up going for the event filter route and it works beautifully. Other than the exact syntax the approach also feels pretty intuitive which I like.

  • 0 Votes
    2 Posts
    758 Views
    mrjjM

    Hi
    Normally you use signals and slots.
    Like when TcpServer got a connection it calls a slot in mainwindow.
    You set it up with connect.

    http://doc.qt.io/qt-5/signalsandslots.html

    http://www.bogotobogo.com/Qt/Qt5_QTcpServer_Client_Server.php
    http://www.bogotobogo.com/Qt/Qt5_QTcpServer_Multithreaded_Client_Server.php

  • 0 Votes
    10 Posts
    5k Views
    kshegunovK

    @fortyff said in Undefined referance to class::function:

    There are the same errors occured in the "esimplelabel.cpp" file, but I didn't write down here, since it'll consume too much place.

    Make sure you have all virtual functions that are declared defined. While a declaration of a regular function without a definition is perfectly valid (until it's called), that's not true for virtual methods.

  • 0 Votes
    6 Posts
    3k Views
    SGaistS

    Just adding a header file here won't help much and you are doing it the wrong way around.

    Why should your EmployeeInfo class know anything from MainWindow ? That's only going to create a tight coupling and the time you'll want to change MainWindow for something else, you'll also have to change EmployeeInfo.

    If you are going to show EmployeeInfo from MainWindow, add setters to EmployeeInfo that you'll use to update its content before showing it like already suggested by @mjsurette or use properties/signals and slots.

  • 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
    4 Posts
    1k Views
    mrjjM

    Hi
    Just a note first
    Having
    class SerialPort : public QObject
    and then
    QSerialPort *serialPort;
    Where only diffence is capital S to the main class is just confusing.

    anyway, why is the issue with
    settings(new SettingsDialog()),

    did you declare it as
    void settings(SettingsDialog *mydialog)

    Im not sure what you dont understand.

    To use a pointer to a class in another class, you simply give the pointer to the other class and it can use it

    class B {}; class A { B* mykeptBpointer; setB(B* myb) { mykeptBpointer = myb; } void DoB { mykeptBpointer->xxxx(); }; A mya; B* myb = new B; mya.setB(b);

    oh, is
    settings(new SettingsDialog())
    rather
    settings = new SettingsDialog();

  • 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
    7 Posts
    19k Views
    R

    @alex_malyu Thanks very much that's what I was missing.
    To get it working I removed the include for DifficultyAnalyser in the SokoGenerator header file
    #include "DifficultyAnalyser"

    I simply the following in the SokoGenerator header
    class DifficultyAnalyser;
    DifficultyAnalyser* diffAnalyser;

    I then included the DifficultyAnalyser header in the SokoGenerator cpp file, and created a new instance of it
    #include "difficultyanalyser.h"
    diffAnalyser = new DifficultyAnalyser;

    And in the header for DifficultyAnalyser I included SokoGenerator
    #include "SokoGenerator.h"

    Thanks for your help!