Thursday, November 20th 2008, 4:12pm UTC

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Sunday, April 20th 2008, 6:00pm

Problems with SLOTs...Help would be appreciated

Hello there
I seem to be encountering a linker error from GNU, whereby I'm getting an undefined reference which seems to think I've declared but did not implement a virtual method. In my case, I believe I've implemented all the functions thereafter. The reasoning behind creating this overloaded class is to further define slots to be used to update the QLineEdit relative to the buttons, otherwise if Qapplication isn't inherited another slot we'll get the following error when loading onto the board.

Object::connect: No such slot QApplication::setValue_1()
Object::connect: (receiver name: '2nd')

I believe the issue is strongly tied to my constructor and have tried writing the following constructor to alleviate the vtable problem (seen below):

MyClass::MyClass(int & argc, char ** argv) : QApplication(argc,argv) {}

I would really appreciate anybody out there that could help.
-Jeff

jefflong@vlsi42:~/qt_sandbox/2nd$ make
arm-linux-g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED -I../../qt-embedded-linux-opensource-src-4.4.0-rc1/mkspecs/qws/linux-arm-g++ -I. -I../../qt-embedded-linux-opensource-src-4.4.0-rc1/include/QtCore -I../../qt-embedded-linux-opensource-src-4.4.0-rc1/include/QtCore -I../../qt-embedded-linux-opensource-src-4.4.0-rc1/include/QtNetwork -I../../qt-embedded-linux-opensource-src-4.4.0-rc1/include/QtNetwork -I../../qt-embedded-linux-opensource-src-4.4.0-rc1/include/QtGui -I../../qt-embedded-linux-opensource-src-4.4.0-rc1/include/QtGui -I../../qt-embedded-linux-opensource-src-4.4.0-rc1/include -I. -I. -I. -o main.o main.cpp
arm-linux-g++ -Wl,-rpath,/usr/lib/qt-4.4.0/lib -o 2nd main.o -L/usr/lib/qt-4.4.0/lib -lQtGui -L/home/jefflong/qt-embedded-linux-opensource-src-4.4.0-rc1/lib -lts -lQtNetwork -lQtCore -lz -lm -lrt -ldl -lpthread
main.o: In function `main':
main.cpp:(.text+0x57c): undefined reference to `vtable for MyClass'
collect2: ld returned 1 exit status
make: *** [2nd] Error 1

//start of code
#include <QApplication>
#include <QPushButton>
#include <QWidget>
#include <QString>
#include <QIcon>

#include <QLineEdit>
#include <QtGui>
#include <QLCDNumber>
#include <QAction>
#include <QToolBar>
#include <QMainWindow>

#define BUTTON_X_MIN 0
#define BUTTON_Y_MIN 0
#define BUTTON_HEIGHT 60
#define BUTTON_WIDTH 60
#define WINDOW_HEIGHT 300
#define WINDOW_WIDTH 600
#define NUMBER_ICONS 12
const QString rsrcPath = ":/images";

char keys[] = {'1','2','3','4','5','6','7','8','9','*','0','#'};
QString temp,LCD_Feed = "hello";
int LCD_Count = 0;


class MyClass : public QApplication
{
Q_OBJECT
public:
MyClass(int & argc, char ** argv) : QApplication(argc,argv) { }
public slots:
void setValue_1();
};
int main(int argc, char *argv[])
{
// QApplication app(argc, argv);
MyClass app(argc, argv);
QWidget window;
window.resize(WINDOW_WIDTH, WINDOW_HEIGHT);

QIcon * button_icons[NUMBER_ICONS];
QPushButton * buttons[NUMBER_ICONS];

int counter;
char temp[128];
int row = 0;

for(counter=0; counter < NUMBER_ICONS; ++counter)
{
if( counter % 3 == 0 && counter > 0)
++row;

sprintf(temp,"images/number_%c.png",keys[counter]);
button_icons[counter] = new QIcon(temp);
buttons[counter] = new QPushButton(*button_icons[counter],NULL,&window);
buttons[counter]->setGeometry(BUTTON_X_MIN + (counter % 3) * BUTTON_WIDTH,BUTTON_Y_MIN+row*BUTTON_HEIGHT,BUTTON_WIDTH,BUTTON_HEIGHT);
// QObject:: connect(buttons[counter], SIGNAL(clicked()), &app, SLOT(quit()));

}
QObject::connect(buttons[1], SIGNAL(clicked()), &app, SLOT(setValue_1()));
// QObject::connect(buttons[2], SIGNAL(clicked()), &app, SLOT(quit()));
// QObject::connect(buttons[3], SIGNAL(clicked()), &app, SLOT(quit()));
// QObject::connect(buttons[4], SIGNAL(clicked()), &app, SLOT(quit()));
// QObject::connect(buttons[5], SIGNAL(clicked()), &app, SLOT(quit()));
// QObject::connect(buttons[6], SIGNAL(clicked()), &app, SLOT(quit()));
// QObject::connect(buttons[7], SIGNAL(clicked()), &app, SLOT(quit()));
// QObject::connect(buttons[8], SIGNAL(clicked()), &app, SLOT(quit()));
// QObject::connect(buttons[9], SIGNAL(clicked()), &app, SLOT(quit()));
// QObject::connect(buttons[10], SIGNAL(clicked()), &app, SLOT(quit()));
// QObject::connect(buttons[11], SIGNAL(clicked()), &app, SLOT(quit()));
// QObject::connect(buttons[12], SIGNAL(triggered()), &app, SLOT(quit()));

QLineEdit *theLCD;
theLCD = new QLineEdit(LCD_Feed,&window);
theLCD->setGeometry(200,150,80,40);

theLCD->setAlignment(Qt::AlignHCenter);

//echoLineEdit->setEchoMode(QLineEdit::phone_number);//is this placed here or elsewhere

window.show();
return app.exec();
}

void MyClass::setValue_1()
{
temp = "1";
// setValue(temp);

switch(LCD_Count){
case 0:
LCD_Feed.append(";(";);
LCD_Feed.append(temp);
LCD_Count = 2;
break;
case 3:
LCD_Feed.append(temp);
LCD_Feed.append(";)";);
LCD_Count = 6;
break;
case 8:

LCD_Feed.append("-";);
LCD_Feed.append(temp);
LCD_Count = 10;
break;
case 14:
LCD_Feed = " ";
LCD_Count = 0;
break;
default:
LCD_Feed.append(temp);
LCD_Count++;
break;
}
}
  • Go to the top of the page

2

Sunday, April 20th 2008, 7:32pm

Object::connect: No such slot QApplication::setValue_1()

Ok, so I found Q_Object wasn't necessary for a qapplication creating the wrapper class, but am uncertain as to why there is still a complaint of:

root@gumstix-custom-verdex:~/qt_apps$ ./2nd -qws
Object::connect: No such slot QApplication::setValue_1()
Object::connect: (receiver name: '2nd')

when loading onto the gumstix board. If anybody could shed any light on this, I would sincerely be appreciative.
Thanks,
Jeff


#include <QApplication>
#include <QPushButton>
#include <QWidget>
#include <QString>
#include <QIcon>

#include <QLineEdit>
#include <QtGui>
#include <QLCDNumber>
#include <QAction>
#include <QToolBar>
#include <QMainWindow>

#define BUTTON_X_MIN 0
#define BUTTON_Y_MIN 0
#define BUTTON_HEIGHT 60
#define BUTTON_WIDTH 60
#define WINDOW_HEIGHT 300
#define WINDOW_WIDTH 600
#define NUMBER_ICONS 12
const QString rsrcPath = ":/images";

char keys[] = {'1','2','3','4','5','6','7','8','9','*','0','#'};
QString temp,LCD_Feed = "hello";
int LCD_Count = 0;


class MyClass : public QApplication
{
// Q_OBJECT
public:
MyClass(int & argc, char ** argv) : QApplication(argc,argv) { }
public slots:
void setValue_1();
};
int main(int argc, char *argv[])
{
// QApplication app(argc, argv);
MyClass app(argc, argv);
QWidget window;
window.resize(WINDOW_WIDTH, WINDOW_HEIGHT);
app.setOverrideCursor(QCursor(Qt::BlankCursor));

QIcon * button_icons[NUMBER_ICONS];
QPushButton * buttons[NUMBER_ICONS];

int counter;
char temp[128];
int row = 0;

for(counter=0; counter < NUMBER_ICONS; ++counter)
{
if( counter % 3 == 0 && counter > 0)
++row;

sprintf(temp,"images/number_%c.png",keys[counter]);
button_icons[counter] = new QIcon(temp);
buttons[counter] = new QPushButton(*button_icons[counter],NULL,&window);
buttons[counter]->setGeometry(BUTTON_X_MIN + (counter % 3) * BUTTON_WIDTH,BUTTON_Y_MIN+row*BUTTON_HEIGHT,BUTTON_WIDTH,BUTTON_HEIGHT);
// QObject:: connect(buttons[counter], SIGNAL(clicked()), &app, SLOT(quit()));

}
QObject::connect(buttons[1], SIGNAL(clicked()), &app, SLOT(setValue_1()));
// QObject::connect(buttons[2], SIGNAL(clicked()), &app, SLOT(quit()));
// QObject::connect(buttons[3], SIGNAL(clicked()), &app, SLOT(quit()));
// QObject::connect(buttons[4], SIGNAL(clicked()), &app, SLOT(quit()));
// QObject::connect(buttons[5], SIGNAL(clicked()), &app, SLOT(quit()));
// QObject::connect(buttons[6], SIGNAL(clicked()), &app, SLOT(quit()));
// QObject::connect(buttons[7], SIGNAL(clicked()), &app, SLOT(quit()));
// QObject::connect(buttons[8], SIGNAL(clicked()), &app, SLOT(quit()));
// QObject::connect(buttons[9], SIGNAL(clicked()), &app, SLOT(quit()));
// QObject::connect(buttons[10], SIGNAL(clicked()), &app, SLOT(quit()));
// QObject::connect(buttons[11], SIGNAL(clicked()), &app, SLOT(quit()));
// QObject::connect(buttons[12], SIGNAL(triggered()), &app, SLOT(quit()));

QLineEdit *theLCD;
theLCD = new QLineEdit(LCD_Feed,&window);
theLCD->setGeometry(200,150,80,40);

theLCD->setAlignment(Qt::AlignHCenter);

//echoLineEdit->setEchoMode(QLineEdit::phone_number);//is this placed here or elsewhere


//this moves the application prior to showing, might use this with the clock (if feasible)
//MyApp.move(QPoint(0,0));
// MyApp.show();

window.show();
return app.exec();
}

void MyClass::setValue_1()
{
temp = "1";
// setValue(temp);

switch(LCD_Count){
case 0:
LCD_Feed.append("(");
LCD_Feed.append(temp);
LCD_Count = 2;
break;
case 3:
LCD_Feed.append(temp);
LCD_Feed.append(")");
LCD_Count = 6;
break;
case 8:

LCD_Feed.append("-");
LCD_Feed.append(temp);
LCD_Count = 10;
break;
case 14:
LCD_Feed = " ";
LCD_Count = 0;
break;
default:
LCD_Feed.append(temp);
LCD_Count++;
break;
}
}
  • Go to the top of the page

Messenger

Intermediate

Posts: 426

Location: Lt

3

Monday, April 21st 2008, 6:05am

RE: Object::connect: No such slot QApplication::setValue_1()

Because new class must be processed by moc (meta object compiler). It processes only header files (can process and source files, but only if called manually (for example in makefile)). Move class declaration to header file and include it in the project.

http://doc.trolltech.com/4.3/moc.html#moc
Fighting fire with fire.

This post has been edited 1 times, last edit by "Messenger" (Apr 21st 2008, 6:05am)

  • Go to the top of the page

Rate this thread