We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,337 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

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

3
Contributors
3
Replies
11 Months
Discussion Span
5 Months Ago
Last Updated
4
Views
Question
Answered
James19142
Light Poster
38 posts since Oct 2009
Reputation Points: 6
Solved Threads: 0
Skill Endorsements: 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: 205
Skill Endorsements: 8

Call by reference method is good here.
Try it.

chikkupa
Newbie Poster
20 posts since Apr 2010
Reputation Points: 10
Solved Threads: 3
Skill Endorsements: 0
Question Answered as of 5 Months Ago by chikkupa and daviddoria

sorry about replying so late, i didnt under your answers because i didnt understand the concept of pointers and purposely disabled copy constructors when posting my question

James19142
Light Poster
38 posts since Oct 2009
Reputation Points: 6
Solved Threads: 0
Skill Endorsements: 0

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0744 seconds using 2.7MB