Hi,
I've created a GUI application and I'd like to convert it into a CONSOLE application. I took out some lines (see //) and addes some (see //ADDED). However, the simple test program failed to compile with this error message: "main.cpp:29: error: ‘myFunction’ was not declared in this scope". Below are my main.cpp, functions.cpp and tom.h
main.cpp
#include <QCoreApplication>//ADD
#include <QApplication>
#include <QtGui>
#include "tom.h"
#include "functions.cpp"
{
//mainLayout = new QVBoxLayout;
//buttonLayout = new QHBoxLayout;
//runButton = new QPushButton("run");
//connect(runButton, SIGNAL(clicked()), this, SLOT(myFunction()));
//mainLayout->addLayout(buttonLayout);
//buttonLayout->addWidget(runButton);
//setLayout(mainLayout);
}
////////////////////////////////////////////////////////////
int main(int argc, char *argv[])
{
//QApplication application(argc, argv);
myFunction();//ADD
//Widget window;
//window.show();
//return application.exec();
return 0;//ADD
}
#include <QCoreApplication>//ADD
#include <QApplication>
#include <QtGui>
#include "tom.h"
#include "functions.cpp"
MyWidget::MyWidget(QWidget* parent): QWidget(parent)
{
//mainLayout = new QVBoxLayout;
//buttonLayout = new QHBoxLayout;
//runButton = new QPushButton("run");
//connect(runButton, SIGNAL(clicked()), this, SLOT(myFunction()));
//mainLayout->addLayout(buttonLayout);
//buttonLayout->addWidget(runButton);
//setLayout(mainLayout);
}
////////////////////////////////////////////////////////////
int main(int argc, char *argv[])
{
//QApplication application(argc, argv);
QCoreApplication application(argc, argv);//ADD
myFunction();//ADD
//Widget window;
//window.show();
//return application.exec();
return 0;//ADD
}
To copy to clipboard, switch view to plain text mode
functions.cpp
#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;
/////////////////////////////////////////////////////
void MyWidget::myFunction()
{
FILE *output; if((output=fopen("output.txt","w")) == 0) {exit(1);}
fprintf(output,"hello\n");
fclose(output);
}
#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;
/////////////////////////////////////////////////////
void MyWidget::myFunction()
{
FILE *output; if((output=fopen("output.txt","w")) == 0) {exit(1);}
fprintf(output,"hello\n");
fclose(output);
}
To copy to clipboard, switch view to plain text mode
tom.h
#ifndef TOM_H
#define TOM_H
#include <QtGui>
{
Q_OBJECT
public:
void myFunction();//ADD
public slots:
//void myFunction();
signals:
protected:
private:
//QVBoxLayout* mainLayout;
//QHBoxLayout* buttonLayout;
//QPushButton* runButton;
};
#endif
#ifndef TOM_H
#define TOM_H
#include <QtGui>
class MyWidget : public QWidget
{
Q_OBJECT
public:
MyWidget (QWidget* parent = 0);
void myFunction();//ADD
public slots:
//void myFunction();
signals:
protected:
private:
//QVBoxLayout* mainLayout;
//QHBoxLayout* buttonLayout;
//QPushButton* runButton;
};
#endif
To copy to clipboard, switch view to plain text mode
I'd be most thankful for any help!
Bookmarks