954,487 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

QT classes as arguments

in this program i'm writing the functions that have qt classes as parameters Qlabel, QSpinbox, etc. are causing compile errors, my other functions work fine

i get the same 2 errors for each QT object i use as an argument

this is the function definition that uses QT classes as 3 of the parameters the first isnt

void fraction::displayfraction(fraction toDis, QLabel nWhole, QLabel nNum, QLabel nDen)
 {
   nWhole.setText(QString::number(toDis.Whle()));
   nNum.setText(QString::number(toDis.Num()));
   nDen.setText(QString::number(toDis.Den()));
 }


this is a test function call that causes the error

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    fraction myfraction(7,4,5);
    QLabel d;
    QLabel n; 
    QLabel w;
    /*error function*/myfraction.displayfraction(myfraction,w,n,d);
}


i get the same 2 errors for each QT object i use as an argument

C:\Users\James\programs\FrctnCltrV3-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Release\..\..\..\..\QtSDK\Desktop\Qt\4.7.4\mingw\include\QtGui\qlabel.h:165: error: 'QLabel::QLabel(const QLabel&)' is private

C:\Users\James\programs\FrctnCltrV3-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Release\..\FrctnCltrV3\mainwindow.cpp:14: error: initializing argument 2 of 'void fraction::displayfraction(fraction, QLabel, QLabel, QLabel)'

i'm 17 and kinda new to programming so the solution could be obvious, i might not find it

James19142
Newbie Poster
18 posts since Oct 2009
Reputation Points: 6
Solved Threads: 0
 

QLabel::QLabel(const QLabel&) is called the copy constructor, and it is indeed private, so you cannot use it. You are trying to use it by copying your object when you pass it to the function. You should accept a const reference to the object instead:

void Test(const QLabel& yourLabel)

David

daviddoria
Posting Virtuoso
1,996 posts since Feb 2008
Reputation Points: 437
Solved Threads: 204
 

Call by reference method is good here.
Try it.

chikkupa
Newbie Poster
20 posts since Apr 2010
Reputation Points: 10
Solved Threads: 2
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: