PDA

View Full Version : collect2: ld returned 1 exit status -- working with toolbars



ctote
16th February 2010, 08:34
so i'm trying to implement some menus into my programs -- i have to be doing it the hard way. Here's my code in its entirety ... please, someone tell me there's an easier way!


#ifndef JAUS_H
#define JAUS_H

#include <QMainWindow>
#include <QVBoxLayout>

namespace Ui {
class jaus;
}

class jaus : public QMainWindow {
Q_OBJECT
public:
jaus();
~jaus();

protected:
void changeEvent(QEvent *e);
void contextMenuEvent(QContextMenuEvent *event);

private:
Ui::jaus *ui;

void createActions();
void createMenus();

QMenu *fileMenu;
QMenu *dataMenu;
QMenu *helpMenu;
QAction *exitAct;
QAction *startLogAct;
QAction *stopLogAct;
QAction *debugAct;
QAction *aboutAct;

private slots:
void exit();
void startLog();
void stopLog();
void debug();
void about();

};

#endif // JAUS_H



#include "jaus.h"
#include "ui_jaus.h"

jaus::jaus()
{
QWidget *widget = new QWidget;
setCentralWidget(widget);

QWidget *topFiller = new QWidget;
topFiller->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

QWidget *bottomFiller = new QWidget;
bottomFiller->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

QVBoxLayout *layout = new QVBoxLayout;
layout->setMargin(5);
layout->addWidget(topFiller);
layout->addWidget(bottomFiller);
widget->setLayout(layout);

createActions();
createMenus();

QString message = tr("JAUS Communicator - Version 0.1");
statusBar()->showMessage(message);
}


jaus::~jaus()
{
delete ui;
}

void jaus::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}

void jaus::createActions()
{
exitAct = new QAction(tr("&Exit"), this);
exitAct->setStatusTip(tr("Exit the application"));
connect(exitAct, SIGNAL(triggered()), this, SLOT(exit()));

startLogAct = new QAction(tr("&Logging"), this);
startLogAct->setStatusTip(tr("Enables Logging"));
connect(startLogAct, SIGNAL(triggered()), this, SLOT(startLog()));

debugAct = new QAction(tr("&Debug"), this);
debugAct->setStatusTip(tr("Turns Debugging On"));
connect(debugAct, SIGNAL(triggered()), this, SLOT(debug()));

aboutAct = new QAction(tr("&About"), this);;
connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
}

void jaus::createMenus()
{
fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(exitAct);
fileMenu->addSeparator();

dataMenu = menuBar()->addMenu(tr("&Data"));
dataMenu->addAction(startLogAct);
dataMenu->addAction(debugAct);
dataMenu->addSeparator();

helpMenu = menuBar()->addMenu(tr("&Help"));
helpMenu->addAction(aboutAct);
}

void jaus::about()
{

}

void jaus::exit()
{

}

void jaus::debug()
{

}


void jaus::startLog()
{

}

void jaus::stopLog()
{

}



#include <QtGui/QApplication>
#include "jaus.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
jaus w;
w.show();
return a.exec();
}


When I compile this code I get the collect2: ld returned 1 exit status error message. I have no clue what this means, but hopefully I can find an easier way (maybe a drag/drop option??) to add menus to my programs. Thanks for any help!!

spirit
16th February 2010, 08:58
I don't see where you allocates memory for ui, but you are trying to call some ui methods in jaus::changeEvent. it must lead to crash.

faldzip
16th February 2010, 09:18
You can create your menu in designer.

ctote
16th February 2010, 18:26
That would be great - can you tell me how? I couldn't find it anywhere

been_1990
16th February 2010, 22:25
http://qt.nokia.com/doc/4.0/designer-manual.html