PDA

View Full Version : Issue using connect, what am I missing?



technoViking
11th January 2010, 04:48
hi guys,

I'm doing a simple signal/slot connection and I'm not sure why I keep getting this message:
C:/Users/Cory/Desktop/Dev/Web/webwidget.cpp:18: error: expected constructor, destructor, or type conversion before '(' token

I get this on both the connections here:


connect(ui->webView, SIGNAL(loadFinished(bool)), SLOT(adjustLocation()));
connect(ui->locationEdit, SIGNAL(returnPressed()), SLOT(changeLocation()));



Here is the full code:



//webwidget.cpp
#include "webwidget.h"
#include "ui_webwidget.h"

WebWidget::WebWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::WebWidget)
{
ui->setupUi(this);
}


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


connect(ui->webView, SIGNAL(loadFinished(bool)), SLOT(adjustLocation()));
connect(ui->locationEdit, SIGNAL(returnPressed()), SLOT(changeLocation()));




void WebWidget::adjustLocation()
{
ui->locationEdit->setText(ui->webView->url().toString());

}

void WebWidget::changeLocation()
{
QUrl url = QUrl(ui->locationEdit->text());
ui->webView->load(url);
ui->webView->setFocus();
}


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





//webwidget.h
#ifndef WEBWIDGET_H
#define WEBWIDGET_H

#include <QWidget>
class QWebView;

namespace Ui {
class WebWidget;
}

class WebWidget : public QWidget {
Q_OBJECT
public:
WebWidget(QWidget *parent = 0);
~WebWidget();

protected:
void changeEvent(QEvent *e);
void adjustLocation();
void changeLocation();

private:
Ui::WebWidget *ui;
};

#endif // WEBWIDGET_H



I'm using qtcreator thats why you see me doing ui-> to reference the controls.


Any help would be great.


Thanks.

technoViking
11th January 2010, 05:11
fixed it. I had to move the connects to the constructor and add slots to the funcitons.