user294664
user294664

Reputation: 127

Compilation error in C++ Qt creator project

I'm new to programming. I downloaded Qt project repository from Git hub and tried to build it on my Ubuntu 14.04. I got some errors when I tried to compile it. I'm using Qt5 and the project file is at least 5 year old. Code is as below,

#include <QtGui>

#include "mainwindow.h"        
MainWindow::MainWindow(QWidget *parent)
    : QDialog(parent)
{
showMaximized();
A = new FiniteElements;
B = new QwtBeginner;
browseButton = createButton(tr("&Open"), SLOT(browse()));

QGridLayout *mainLayout = new QGridLayout;

mainLayout->addWidget(B, 0, 0);
mainLayout->addWidget(browseButton, 0, 1);

setLayout(mainLayout);

setWindowTitle(tr("L4V14_oapsois by Mikhail Krishtop"));
}

void MainWindow::browse()
{
QString filepath = QFileDialog::getOpenFileName(this,tr("Select input      datafile"),QDir::currentPath());

if (!filepath.isEmpty()) {
    std::string str = std::string(filepath.toAscii().data());
    const char * stuff = str.c_str();
    A->SetFN(stuff);
    A->evaluate();
           B->eval(A->GetXArray(),A->GetYArray(),A->GetN(),A->GetTriangles(),stuff,
            A->GetTArray(),A->GetX(),A->GetY(),A->GetResultTemp());
}
}

QPushButton *MainWindow::createButton(const QString &text, const char *member)
{
QPushButton *button = new QPushButton(text);
connect(button, SIGNAL(clicked()), this, member);
return button;
}

I got the following errors,
error: QGridLayout was not declared in this space
error: QFileDialog has not been declared
error: invalid use of incomplete type 'class QPushButton'

Could anyone help me? ^

Upvotes: 2

Views: 1263

Answers (2)

Gio
Gio

Reputation: 3340

You are missing a number of includes, note that QtGui does not provide you with QGridLayout, QFileDialog or QPushButton. According to the Qt documentation:

The Qt GUI module provides classes for windowing system integration, event handling, OpenGL and OpenGL ES integration, 2D graphics, imaging, fonts and typography. These classes are used internally by Qt's user interface technologies and can also be used directly, for instance to write applications using low-level OpenGL ES graphics APIs.

See here for a full overview of the classes which are included with QtGui. Hence in conclusion, as pointed out Thx. @HAG, you need add the following includes:

#include <QGridLayout>
#include <QFileDialog>
#include <QPushButton>

Alternatively you can just include the QtWidgets class, which will provide you with all of these classes.

#include <QtWidgets>

See here, for a full overview of the classes which are available by including QtWidgets.

Upvotes: 1

HazemGomaa
HazemGomaa

Reputation: 1630

Try to include the missing headers

    #include <QGridLayout>
    #include <QFileDialog>
    #include <QPushButton>

Upvotes: 3

Related Questions