Cannot call function without object
Hi. I've got a problem. I have public member function called clear() which looks like this:
Code:
void MainWindow::clear()
{
tableWidget->clear();
tableWidget_2->clear();
tableWidget_3->clear();
tableWidget_4->clear();
tableWidget_5->clear();
tableWidget_6->clear();
tableWidget_7->clear();
}
and when I call it in another member function
Code:
MainWindow::clear()
There appear error that I can't call member function MainWindow::clear() without object. What's the problem about? Regards
Re: Cannot call function without object
You need something like this:
or simply call clear().
The class resolution operator ( :: ) is used when calling static functions.
But usually, when you're using other member functions, you can just call them. Using "this" is a well known ( some say bad ) Java practice.
Regards
Re: Cannot call function without object
I tried to use only call() but there appear error that clear() is not declared
Re: Cannot call function without object
Quote:
Originally Posted by
Salazaar
I tried to use only call() but there appear error that clear() is not declared
Where do you want to invoke MainWindow::clear() (i.e. in what method or function)?
Re: Cannot call function without object
Quote:
Originally Posted by
marcel
Using "this" is a well known ( some say bad ) Java practice.
Not only Java, but Python and PHP too. It's completely unnecessary and makes your code look ugly, but I wonder whether I could have any positive outcomes.
Re: Cannot call function without object
If the clear function is within QMainWindow why not put the following in your QMainWindow header file :
Code:
extern MainWindow *theApp;
and then in your .cpp file for MainWindow, someplace at the top :
Code:
MainWindow *theApp; // I'm presuming MainWindow derives from QMainWindow...
and in your constructor :
This way, you can make calls to the clear function from other classes by :
as long as you include the MainWindow header file...
Regards,
Steve