I just constructed a project out of your code, and it compiles, links and executes as expected. I did make some minor adjustments (some formatting and streamlining the includes for a bit faster build). Here's what I have:
#ifndef SLOTS_H
#define SLOTS_H
#include <QWidget>
{
Q_OBJECT
public:
public slots:
void slotButtonClicked();
};
#endif //SLOTS_H
#ifndef SLOTS_H
#define SLOTS_H
#include <QWidget>
class QLineEdit;
class QPushButton;
class myCanvas : public QWidget
{
Q_OBJECT
QLineEdit *lineedit;
QPushButton *pushbutton;
public:
myCanvas (QWidget * parent = 0);
public slots:
void slotButtonClicked();
};
#endif //SLOTS_H
To copy to clipboard, switch view to plain text mode
/#include "slots.h"
#include <QPushButton>
#include <QLineEdit>
#include <QVBoxLayout>
#include <QApplication>
connect(pushbutton, SIGNAL(clicked()), this, SLOT(slotButtonClicked()));
layout->addWidget(lineedit);
layout->addWidget(pushbutton);
setLayout(layout);
}
void myCanvas::slotButtonClicked()
{
QString theText
= lineedit
->text
();
}
int main (int argc, char * argv[])
{
myCanvas bob;
bob.show();
return app.exec();
}
/#include "slots.h"
#include <QPushButton>
#include <QLineEdit>
#include <QVBoxLayout>
#include <QApplication>
myCanvas::myCanvas(QWidget *parent):QWidget(parent){
lineedit = new QLineEdit(this);
pushbutton = new QPushButton("Enter", this);
connect(pushbutton, SIGNAL(clicked()), this, SLOT(slotButtonClicked()));
QVBoxLayout * layout = new QVBoxLayout;
layout->addWidget(lineedit);
layout->addWidget(pushbutton);
setLayout(layout);
}
void myCanvas::slotButtonClicked()
{
QString theText = lineedit->text();
}
int main (int argc, char * argv[])
{
QApplication app (argc, argv);
myCanvas bob;
bob.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
It worked before and after the alterations. What does your .pro look like?
TEMPLATE = app
CONFIG += qt
QT += gui
SOURCES += \
connect.cpp
HEADERS += \
slots.h
TEMPLATE = app
CONFIG += qt
QT += gui
SOURCES += \
connect.cpp
HEADERS += \
slots.h
To copy to clipboard, switch view to plain text mode
Bookmarks