1
votes

I have been battling with an issue on Qt for a while now and figured I'd come by here to see if anyone had any solutions.

I've created a GUI using the QT tools and have programmed all of the functions for each respective thing. However, I can't seem to successfully rectify the following issue:

C:\Python34\2SprayCoater\mainwindow.cpp:11: error: no 'int mainwindow::MainWindow(QWidget*)' member function declared in class 'mainwindow' mainwindow::MainWindow(QWidget *parent):QMainWindow(parent)

The part of code from the library in question is:

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {
class MainWindow;
}

class mainwindow : public QMainWindow
{
    Q_OBJECT

    public:
    explicit mainwindow(QWidget *parent = 0);
    ~mainwindow();

And the reference to this code in the cpp file is:

#include "mainwindow.h"
#include <QApplication>

#include "main.cpp"
#include <QtSerialPort/QSerialPort>
#include <QtCore/QCoreApplication>
#include <QtCore/QDebug>



mainwindow::MainWindow(QWidget *parent):QMainWindow(parent)

{
    ui.setupUi(this);
}

I tried to fix this by simply changing explicit

mainwindow(QWidget *parent = 0);

in the header file to

explicit mainwindow(QWidget *parent = 0):QMainWindow(parent);

Which just ends up creating a slough of different issues, but fixes the original. What am I missing? Thanks in advance.

1
Why do you include main.cpp in mainwindow.cpp?eyllanesc
I found that when I do it any other way I get compiling errors with serial port initialization. Putting it in main and referencing then including main.cpp in mainwindow.cpp fixed this.Zachary Melnyk
You could share the entire project through github, drive or similar.eyllanesc
You should not modify the things that the IDE generates, but you know what it is for.eyllanesc

1 Answers

1
votes

The problem is generated because you removed some necessary headers, for example:

#include "ui_mainwindow.h"

This is generated by the .ui file, ie the design is converted to code before compiling it. The ui attribute needs that file, also ui is a pointer so to access its methods you must use ->. You must change:

ui.setupUi(this);

to

ui->setupUi(this);

Another serious problem is that you have renamed mainwindow to MainWindow in the constructor.

explicit mainwindow(QWidget *parent = 0);

mainwindow::MainWindow(QWidget *parent):QMainWindow(parent)
            [here]