Qt-interest Archive, September 2002
Linking errors
Message 1 in thread
Hello, I'm new to qt and new to C++. I am in the process of reading
Stroustrup (thought I'd mention that because I'm pretty sure I would get
that from someone). I learn best while doing, so I thought I would post
this problem in the hopes that someone can help me so I can continue to
make progress on my little test program. I'm getting an error when I
try to ling all my object files into an exacutable.
These are the errors.
command run:
gcc LSQLdbList.o LSQLstructureTable.o LSQLdataWindow.o
LSQLprocessTable.o LSQLvariableTable.o LSQLtableEdit.o
LSQLdbConnection.o LSQL.o -I$QTDIR/include -L$QTDIR/lib -lqt -o LSQL
All the files compile fine to make the object files listed. When I try
to ling them together with the above command I get this error:
LSQLdataWindow.o in function `dataWindow::dataWindow(dbConnection *)':
LSQLdataWindow.o(.text+0x221): undefined reference to
`staticDataTable::staticDataTable( QWidget *, char const *,
dbConnection *)'
collect2: ld returned 1 exit status
here are the files I think need to be seen.
LSQLdataWindow.h
#ifndef __LSQLdataWindow__
#define __LSQLdataWindow__
#include <qwidget.h>
#include <qtabbar.h>
#include <qwidgetstack.h>
#include "LSQLprocessTable.h"
#include "LSQLvariableTable.h"
#include "LSQLtableEdit.h"
#include "LSQLdbList.h"
#include "LSQLdbConnection.h"
//#include "LSQLstructureTable.h"
#include "LSQLstaticDataTable.h"
class dataWindow : public QWidget
{
public:
dataWindow( dbConnection* );
~dataWindow();
protected:
virtual void resizeEvent( QResizeEvent* );
private:
QTabBar* windowMenu;
dbConnection* localDB;
dbList* listView;
QWidgetStack* windowStack;
processTable* processSlide;
variableTable* variableSlide;
tableEdit* editSlide;
staticDataTable* structureSlide;
};
#endif
LSQLdataWindow.cpp:
#include "LSQLdataWindow.h"
dataWindow::dataWindow( dbConnection* passedConnection ) : QWidget( )
{
const char* name = "stack win";
localDB = passedConnection;
listView = new dbList( this, localDB );
windowMenu = new QTabBar( this, "Tab Menu" );
windowStack = new QWidgetStack( this, "Window Stack" );
processSlide = new processTable();
variableSlide = new variableTable();
structureSlide = new staticDataTable( windowStack, name,
localDB );
editSlide = new tableEdit( "newlistings" );
QTab* processTab = new QTab( "Processes" );
QTab* varTab = new QTab( "Server Vars" );
QTab* structureTab = new QTab( "Table Structure" );
QTab* tableTab = new QTab( "Table Data" );
windowMenu->addTab( processTab );
windowMenu->addTab( varTab );
windowMenu->addTab( structureTab );
windowMenu->addTab( tableTab );
windowStack->addWidget( processSlide, -1 );
windowStack->addWidget( variableSlide, -1 );
windowStack->addWidget( structureSlide, -1 );
windowStack->addWidget( editSlide, -1 );
windowStack->raiseWidget( 0 );
listView->setGeometry( 0, 0, 200, this->height( ) );
listView->show();
windowMenu->setGeometry( listView->width(), 0, 400,
windowMenu->height( ) );
windowStack->setGeometry( listView->width(), 24 , this->width( ) -
listView->width(), this->height( ) - 24 );
QObject::connect( windowMenu, SIGNAL( selected( int ) ),
windowStack, SLOT( raiseWidget( int ) ) );
QObject::connect(listView, SIGNAL( dbSelected( const QString& ) ),
localDB, SLOT( changeDB( const QString& ) ) );
QObject::connect(listView, SIGNAL( tableSelected( const QString& )
), editSlide, SLOT( changeTable( const QString& ) ) );
//QObject::connect(listView, SIGNAL( tableSelected( const
QString& ) ), structureSlide, SLOT( changeTable( const QString& ) ) );
}
dataWindow::~dataWindow( )
{
}
void dataWindow::resizeEvent( QResizeEvent* event )
{
windowStack->setGeometry( listView->width(), 24 , this->width( ) -
listView->width(), this->height( ) - 24 );
listView->setGeometry( 0, 0, 200, this->height( ) );
}
LSQLstaticDataTable.h
#ifndef LSQLSTATICDATATABLE_H
#define LSQLSTATICDATATABLE_H
#include <qtable.h>
#include <qwidget.h>
#include <qsqlquery.h>
#include <qstring.h>
#include "LSQLdbConnection.h"
class staticDataTable : public QTable
{
public:
staticDataTable( QWidget* parent=0, const char* name=0,
dbConnection* passDB=0 );
~staticDataTable( );
void buildTable( );
void setCurrentQuery( QString* );
int getRowSize( );
private:
QSqlQuery* currentQuery;
dbConnection* localDB;
};
#endif
LSQLstaticDataTable.cpp:
#include "LSQLstaticDataTable.h"
staticDataTable::staticDataTable( QWidget* parentWidget=0, const char*
name=0, dbConnection* passDB=0 ) : QTable( parentWidget, name )
{
localDB = passDB;
}
staticDataTable::~staticDataTable()
{
}
void staticDataTable::buildTable( )
{
if( currentQuery->isActive() )
{
this->setNumCols( staticDataTable::getRowSize( ) );
this->setNumRows( currentQuery->size() );
this->setFocusStyle( QTable::FollowStyle );
this->setSelectionMode( QTable::SingleRow );
int i = 0;
while( currentQuery->next() )
{
int j;
for( j = 0; j < staticDataTable::getRowSize( );
j++ )
{
this->setText( i, j,
currentQuery->value( j ).toString() );
}
i++;
}
for( i = 0; i < staticDataTable::getRowSize( ); i++ )
{
this->setColumnReadOnly( i, true );
this->adjustColumn( i );
}
}
else
{
qDebug( "Failed to create database variable query " );
qWarning( "Failed to open sales database: " +
localDB->getDriverError() );
qWarning( localDB->getDatabaseError() );
}
}
void staticDataTable::setCurrentQuery( QString* passString )
{
currentQuery = new QSqlQuery( QConstString(
passString->unicode(), passString->length() ).string() );
}
int staticDataTable::getRowSize( )
{
int i = 0;
currentQuery->first();
while( currentQuery->next() )
{
i++;
}
return i;
}
Thanks for any help!
Message 2 in thread
Why don't you try actually linking in the object file where staticDataTable
is defined to define the reference?
-----Original Message-----
From: destr0 [mailto:joellist@litriusgroup.com]
Sent: Wednesday, September 04, 2002 11:01 AM
To: qt-interest@trolltech.com
Subject: Linking errors
Hello, I'm new to qt and new to C++. I am in the process of reading
Stroustrup (thought I'd mention that because I'm pretty sure I would get
that from someone). I learn best while doing, so I thought I would post
this problem in the hopes that someone can help me so I can continue to
make progress on my little test program. I'm getting an error when I
try to ling all my object files into an exacutable.
These are the errors.
command run:
gcc LSQLdbList.o LSQLstructureTable.o LSQLdataWindow.o
LSQLprocessTable.o LSQLvariableTable.o LSQLtableEdit.o
LSQLdbConnection.o LSQL.o -I$QTDIR/include -L$QTDIR/lib -lqt -o LSQL
All the files compile fine to make the object files listed. When I try
to ling them together with the above command I get this error:
LSQLdataWindow.o in function `dataWindow::dataWindow(dbConnection *)':
LSQLdataWindow.o(.text+0x221): undefined reference to
`staticDataTable::staticDataTable( QWidget *, char const *,
dbConnection *)'
collect2: ld returned 1 exit status
here are the files I think need to be seen.
LSQLdataWindow.h
#ifndef __LSQLdataWindow__
#define __LSQLdataWindow__
#include <qwidget.h>
#include <qtabbar.h>
#include <qwidgetstack.h>
#include "LSQLprocessTable.h"
#include "LSQLvariableTable.h"
#include "LSQLtableEdit.h"
#include "LSQLdbList.h"
#include "LSQLdbConnection.h"
//#include "LSQLstructureTable.h"
#include "LSQLstaticDataTable.h"
class dataWindow : public QWidget
{
public:
dataWindow( dbConnection* );
~dataWindow();
protected:
virtual void resizeEvent( QResizeEvent* );
private:
QTabBar* windowMenu;
dbConnection* localDB;
dbList* listView;
QWidgetStack* windowStack;
processTable* processSlide;
variableTable* variableSlide;
tableEdit* editSlide;
staticDataTable* structureSlide;
};
#endif
LSQLdataWindow.cpp:
#include "LSQLdataWindow.h"
dataWindow::dataWindow( dbConnection* passedConnection ) : QWidget( )
{
const char* name = "stack win";
localDB = passedConnection;
listView = new dbList( this, localDB );
windowMenu = new QTabBar( this, "Tab Menu" );
windowStack = new QWidgetStack( this, "Window Stack" );
processSlide = new processTable();
variableSlide = new variableTable();
structureSlide = new staticDataTable( windowStack, name,
localDB );
editSlide = new tableEdit( "newlistings" );
QTab* processTab = new QTab( "Processes" );
QTab* varTab = new QTab( "Server Vars" );
QTab* structureTab = new QTab( "Table Structure" );
QTab* tableTab = new QTab( "Table Data" );
windowMenu->addTab( processTab );
windowMenu->addTab( varTab );
windowMenu->addTab( structureTab );
windowMenu->addTab( tableTab );
windowStack->addWidget( processSlide, -1 );
windowStack->addWidget( variableSlide, -1 );
windowStack->addWidget( structureSlide, -1 );
windowStack->addWidget( editSlide, -1 );
windowStack->raiseWidget( 0 );
listView->setGeometry( 0, 0, 200, this->height( ) );
listView->show();
windowMenu->setGeometry( listView->width(), 0, 400,
windowMenu->height( ) );
windowStack->setGeometry( listView->width(), 24 , this->width( ) -
listView->width(), this->height( ) - 24 );
QObject::connect( windowMenu, SIGNAL( selected( int ) ),
windowStack, SLOT( raiseWidget( int ) ) );
QObject::connect(listView, SIGNAL( dbSelected( const QString& ) ),
localDB, SLOT( changeDB( const QString& ) ) );
QObject::connect(listView, SIGNAL( tableSelected( const QString& )
), editSlide, SLOT( changeTable( const QString& ) ) );
//QObject::connect(listView, SIGNAL( tableSelected( const
QString& ) ), structureSlide, SLOT( changeTable( const QString& ) ) );
}
dataWindow::~dataWindow( )
{
}
void dataWindow::resizeEvent( QResizeEvent* event )
{
windowStack->setGeometry( listView->width(), 24 , this->width( ) -
listView->width(), this->height( ) - 24 );
listView->setGeometry( 0, 0, 200, this->height( ) );
}
LSQLstaticDataTable.h
#ifndef LSQLSTATICDATATABLE_H
#define LSQLSTATICDATATABLE_H
#include <qtable.h>
#include <qwidget.h>
#include <qsqlquery.h>
#include <qstring.h>
#include "LSQLdbConnection.h"
class staticDataTable : public QTable
{
public:
staticDataTable( QWidget* parent=0, const char* name=0,
dbConnection* passDB=0 );
~staticDataTable( );
void buildTable( );
void setCurrentQuery( QString* );
int getRowSize( );
private:
QSqlQuery* currentQuery;
dbConnection* localDB;
};
#endif
LSQLstaticDataTable.cpp:
#include "LSQLstaticDataTable.h"
staticDataTable::staticDataTable( QWidget* parentWidget=0, const char*
name=0, dbConnection* passDB=0 ) : QTable( parentWidget, name )
{
localDB = passDB;
}
staticDataTable::~staticDataTable()
{
}
void staticDataTable::buildTable( )
{
if( currentQuery->isActive() )
{
this->setNumCols( staticDataTable::getRowSize( ) );
this->setNumRows( currentQuery->size() );
this->setFocusStyle( QTable::FollowStyle );
this->setSelectionMode( QTable::SingleRow );
int i = 0;
while( currentQuery->next() )
{
int j;
for( j = 0; j < staticDataTable::getRowSize( );
j++ )
{
this->setText( i, j,
currentQuery->value( j ).toString() );
}
i++;
}
for( i = 0; i < staticDataTable::getRowSize( ); i++ )
{
this->setColumnReadOnly( i, true );
this->adjustColumn( i );
}
}
else
{
qDebug( "Failed to create database variable query " );
qWarning( "Failed to open sales database: " +
localDB->getDriverError() );
qWarning( localDB->getDatabaseError() );
}
}
void staticDataTable::setCurrentQuery( QString* passString )
{
currentQuery = new QSqlQuery( QConstString(
passString->unicode(), passString->length() ).string() );
}
int staticDataTable::getRowSize( )
{
int i = 0;
currentQuery->first();
while( currentQuery->next() )
{
i++;
}
return i;
}
Thanks for any help!
--
[ signature omitted ]
Message 3 in thread
Smith, William R wrote:
>Why don't you try actually linking in the object file where staticDataTable
>is defined to define the reference?
>
Ahhh yes...
I love it when I have errors like this. This way I can feel like a
complete ass, instead of just feeling like a partial ass. I've been
trying to figure this out for a day.