Error C2352: illegal call of non-static member function
-
Hi
I am trying to modify some code that someone else wrote. Added two new UI screens.
One is working perfectly.
The other is working, but I need to pass data from a com port to it from another module.
So I figured I would create a function and pass the data to it so that it could parse it and update the local ui-window.newsurvydialog.h
#ifndef NEWSURVEYDIALOG_H
#define NEWSURVEYDIALOG_H#include <QDialog>
#include <QString>
#include <QFile>
#include <QList>
#include <QIcon>
#include "panelconnection.h"
#include "common_defs.h"
//#include "ui_newsurveydialog.h"namespace Ui {
class NewSurveyDialog;
}class NewSurveyDialog : public QDialog
{
Q_OBJECTpublic:
explicit NewSurveyDialog(QWidget *parent = 0 ) ;
~NewSurveyDialog();void setDownloaded(bool flag); bool setSource(QFile &src); bool setSource(QString src); int ConvertRSSI( char * hexRssi ); void parseNewSurveyData( QString str );
newsurveydialog.cpp
void NewSurveyDialog::parseNewSurveyData(
QString str
) {ui->IDC_EDIT_OUTPUT_RAW->append( str );
}
panelconnection.cpp
mData = thread->getData().replace(request.trimmed(), tr("")).trimmed();
qDebug() << "trimmed ==" << mData;mData = thread->getData();
qDebug() << "trimmed ==" << mData;
NewSurveyDialog::parseNewSurveyData( mData );Error message from compiler
.\panelconnection.cpp(315) : error C2352: 'NewSurveyDialog::parseNewSurveyData'
: illegal call of non-static member function
c:\cp3000_suite_latest\src\cp3000_suite\newsurveydialog.h(29) : see declaration of 'NewSurveyDialog::parseNewSurveyData'
NMAKE : fatal error U1077: '"c:\Program Files (x86)\Microsoft Visual Studio 10.0
\VC\BIN\cl.EXE"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"c:\Program Files (x86)\Microsoft Visual Studio 10.0
\VC\BIN\nmake.exe"' : return code '0x2'
Stop.Any assistance would be appreciated.
Also is there a great book that I can order today to help bring me up to speed.
Thanks
Rob -
you are trying to update a window for a non-existent object... You must first create an object of NewSurveyDialog type class and then call the method for that object...
-
the error says it all:
you're trying to access the member function which isn't declared as static.
Since you are using a member inside the function you need to call the method on an instance instead of the static way (with prepended NewSurveyDialog::). -
Thanks for the replies.
I do create an object. I only put in some of the code.
When I declare in newsurveydialog.h as a static
static void parseNewSurveyData( QString str );
I get the following compile errors.
newsurveydialog.cpp
.\newsurveydialog.cpp(85) : error C2227: left of '->IDC_EDIT_OUTPUT_RAW' must point to class/struct/union/generic type
.\newsurveydialog.cpp(85) : error C2227: left of '->append' must point to class/struct/union/generic type
NMAKE : fatal error U1077: '"c:\Program Files (x86)\Microsoft Visual Studio 10.0
\VC\BIN\cl.EXE"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"c:\Program Files (x86)\Microsoft Visual Studio 10.0
\VC\BIN\nmake.exe"' : return code '0x2'
Stop. -
as i wrote in my post: you are accessing a member (ui) inside this function. Thus you can't make it static.
Because you can only access other static members out of a static method. -
Here is the code that creates the ui-> object for ui->IDC_EDIT_OUTPUT_RAW->append( str );
NewSurveyDialog::NewSurveyDialog(QWidget *parent ) :
QDialog(parent),
ui(new Ui::NewSurveyDialog)
{
ui->setupUi(this);// set flags default values m_bNotifyPaused = FALSE; //nConnection = NULL; //connect(ui->buttonOK, SIGNAL(clicked()), SLOT(buttonPressedOK())); connect(ui->IDC_BUTTON_BROWSE_SAVE_SURVEY, SIGNAL(clicked()), SLOT(buttonPressedBrowseSaveSurvey())); connect(ui->StartNewSurvey, SIGNAL(clicked()), SLOT(buttonStartNewSurvey())); connect(ui->PauseAnalysis, SIGNAL(clicked()), SLOT(buttonPauseAnalysis())); //ui->IDC_RSSI_BARGRAPH->setVisible(false); initProgress(-115,-55); updateProgress( -115 ); ui->IDC_RSSI_BARGRAPH->setVisible(true); ui->IDC_EDIT_OUTPUT_RAW->setVisible(true); ui->IDC_REPEATER_ID->insert( gRptrSerialNbr); ui->IDC_PARENT_ID->insert( gMasterID ); nonJoinableCount = 0;
}
-
so how do I pass a data string to newSurveyDialog ?
-
did you read my first post at all? You should use a instance to your object where you want to call the method.
Or you could use SIGNALS/SLOTS to send a string to another object. -
[quote author="rraf02" date="1368194601"]Here is the code that creates the ui-> object for ui->IDC_EDIT_OUTPUT_RAW->append( str );
NewSurveyDialog::NewSurveyDialog(QWidget *parent ) :
QDialog(parent),
ui(new Ui::NewSurveyDialog)
{
ui->setupUi(this);// set flags default values m_bNotifyPaused = FALSE; //nConnection = NULL; //connect(ui->buttonOK, SIGNAL(clicked()), SLOT(buttonPressedOK())); connect(ui->IDC_BUTTON_BROWSE_SAVE_SURVEY, SIGNAL(clicked()), SLOT(buttonPressedBrowseSaveSurvey())); connect(ui->StartNewSurvey, SIGNAL(clicked()), SLOT(buttonStartNewSurvey())); connect(ui->PauseAnalysis, SIGNAL(clicked()), SLOT(buttonPauseAnalysis())); //ui->IDC_RSSI_BARGRAPH->setVisible(false); initProgress(-115,-55); updateProgress( -115 ); ui->IDC_RSSI_BARGRAPH->setVisible(true); ui->IDC_EDIT_OUTPUT_RAW->setVisible(true); ui->IDC_REPEATER_ID->insert( gRptrSerialNbr); ui->IDC_PARENT_ID->insert( gMasterID ); nonJoinableCount = 0;
}[/quote]
That's the code creating an ui-object...
but the method you're calling isn't a member of the ui-class but of your class NewSurveyDialog
-> that's the one you have to instantiate and call the method on its instance -
in pannel connection.cpp you must create an instance of NewSurveyDialog... For example:
@
mData = thread->getData().replace(request.trimmed(), tr(”“)).trimmed();
qDebug() << “trimmed ==” << mData;mData = thread->getData();
qDebug() << “trimmed ==” << mData;
NewSurveyDialog *someName = new NewSurveyDialog(); // This is an instance of a object
somename->parseNewSurveyData(mData); // This is how you call the method for that object
@ -
I'm new at QT and figuring it out as I go, (Reading up and then Trial and Terror).
As my brother said when he was posted to Scotland, I know you are speaking english, but I don't understand a word you are saying. :-)
I thought I already had an instance already created as I am updating the new window, I just need to pass data to it from the com port data stream.
So do you have an example of how I might use SIGNALS/SLOTS to send a string from another object.
I will also try to read up on signals/slots.BTW, thanks for the help.
-
even if you really had created the instance... "NewSurveyDialog::parseNewSurveyData( mData );" is always a static member call
-
Thanks. I will give that a try.