Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved
    1. Home
    2. Tags
    3. class

    Log in to post
    • All categories
    • T

      Unsolved error: no match for 'operator==' (operand types are 'Visitor' and 'const QString')
      General and Desktop • class object c++ • • Tasha

      5
      0
      Votes
      5
      Posts
      3335
      Views

      jsulm

      @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);
    • B

      Solved Class instance is uninitialized
      General and Desktop • c++ qml class instance c4700 • • BoGut

      5
      0
      Votes
      5
      Posts
      448
      Views

      mrjj

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

    • ?

      Unsolved Starting App from other class
      General and Desktop • class start application • • A Former User

      16
      0
      Votes
      16
      Posts
      540
      Views

      jsulm

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

      GraphDataGenerator

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

    • J

      Solved need help SigSegv fault with normal + calculation
      General and Desktop • sigsegv fault signals slot class • • JonnyQB

      9
      0
      Votes
      9
      Posts
      544
      Views

      mrjj

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

    • F

      Solved Error when connecting a custom class and MainWindow
      General and Desktop • class connect connect problem signals slots • • Forfunckle

      4
      0
      Votes
      4
      Posts
      559
      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!

    • oblivioncth

      Solved Why does the const Object returned by QList::at() block access to instance methods?
      General and Desktop • qlist const class object c++ • • oblivioncth

      8
      0
      Votes
      8
      Posts
      1365
      Views

      JKSH

      @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

    • N

      Solved How to draw on Image loaded in a QGraphicsView
      General and Desktop • draw qgraphicsview c++ c++ qt class • • Nico1564

      22
      0
      Votes
      22
      Posts
      11872
      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.

    • T

      Solved Pass data from a new class to main: return type specification for constructor invalid
      General and Desktop • c++ qt class • • TMJJ

      7
      0
      Votes
      7
      Posts
      1974
      Views

      VRonin

      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()
    • K

      Unsolved Connect() uses wrong emitter object.
      General and Desktop • connect connection signal slot class • • Kalado

      7
      0
      Votes
      7
      Posts
      1985
      Views

      Pradeep Kumar

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

    • CybeX

      Unsolved qt - undefined reference to `vtable for myObj' in qt console application - signals and slots
      General and Desktop • qobject macro class vtable qt 5.7 • • CybeX

      11
      0
      Votes
      11
      Posts
      7180
      Views

      D

      @yuvaram

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

    • oblivioncth

      Solved Capturing key press in QGraphicsView within main() function?
      General and Desktop • qgraphicsview qgraphicsscene class main keypressevent • • oblivioncth

      4
      0
      Votes
      4
      Posts
      5489
      Views

      oblivioncth

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

    • Z

      Unsolved Problem with using functions of others class.
      General and Desktop • qt 5.7 class • • Zirk

      2
      0
      Votes
      2
      Posts
      668
      Views

      mrjj

      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

    • fortyff

      Unsolved Undefined referance to class::function
      General and Desktop • qtdesigner qtwidgets undefined refer class • • fortyff

      10
      0
      Votes
      10
      Posts
      4581
      Views

      kshegunov

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

    • ronyNS

      Unsolved Share data between two classes.
      General and Desktop • c++ qt 5.7 c++ windows class • • ronyNS

      6
      0
      Votes
      6
      Posts
      2351
      Views

      SGaist

      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.

    • G

      Unsolved Using the same variable (and its value) in different classes
      General and Desktop • variable class • • gabor53

      11
      0
      Votes
      11
      Posts
      1999
      Views

      SGaist

      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.

    • Basti46

      Solved How to get a class pointer without messing up data.
      General and Desktop • inheritance pointer pointers class • • Basti46

      4
      0
      Votes
      4
      Posts
      1241
      Views

      mrjj

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

    • paul_b

      Unsolved Class variable updating / QLabel | Thread
      General and Desktop • class qlabel updat variable • • paul_b

      2
      0
      Votes
      2
      Posts
      1139
      Views

      SGaist

      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.

    • R

      Solved Forward Declaration of Class and Incomplete Type
      General and Desktop • incomplete type forward declaration class • • RBrNx277

      7
      0
      Votes
      7
      Posts
      16787
      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!

    • oblivioncth

      Solved [New to QT] Possible to refer to UI objects with dot (.) notation?
      General and Desktop • gui objects slots class • • oblivioncth

      3
      0
      Votes
      3
      Posts
      1397
      Views

      oblivioncth

      @JohanSolo

      Ah ok, so it is due to the organization of C++ not Qt, and like you said, the difference of a class instances and pointers.

      It has been long time since I've had to use C++ and I never did anything too advance with it other than a text-based adventure game. I generally am more focused on hardware oriented programing such as with C and Verilog, and MATLAB is the only more software (excluding Arduino interaction) oriented language I have decent experience with.

      Thank you for pointing out why there needs to be a difference. I wasn't familar with pointer usage in C++.

    • T

      [solved]Call class function in another cpp file
      General and Desktop • class header cpp objects • • TheHawk

      16
      0
      Votes
      16
      Posts
      11011
      Views

      T

      My apologies, I will create a new thread. Thanks for all your help! (and putting up with my stuff :) )