(C++) How to cross-compile a Qt Creator project from Ubuntu to a windows executable: example 6: any application, using tweaked Makefile

February 24, 2017 · View on GitHub

 

 

 

 

 

(C++) How to cross-compile a Qt Creator project from Ubuntu to a windows executable: example 6: any application, using tweaked Makefile

 

This is example 6, and a solution of unknown viability in answering the Qt FAQ How to cross-compile a Qt Creator project from Ubuntu to a windows executable?.

 

 

 

 

 

Operating system: Ubuntu 10.04 LTS Lucid Lynx

IDE: Qt Creator 2.0.0

Project type: GUI application

Compiler: G++ 4.4.1

Libraries used:

Project options:

  • Added the additional qmake argument '-spec win32-g++'

 

 

 

 

 

Qt project file

 


#------------------------------------------------- # # Project created by QtCreator 2010-09-28T16:06:49 # #------------------------------------------------- QT       += core gui TARGET = CppQtCrosscompileToWindowsExample6 TEMPLATE = app LIBS += -L/usr/lib -lboost_system -lboost_filesystem SOURCES += main.cpp\         dialog.cpp HEADERS  += dialog.h FORMS    += dialog.ui

 

 

 

 

 

dialog.cpp

 


#include <iostream> #include <string> #include <vector> //--------------------------------------------------------------------------- #include <boost/filesystem.hpp> #include <boost/foreach.hpp> //--------------------------------------------------------------------------- #include "dialog.h" #include "ui_dialog.h" //--------------------------------------------------------------------------- //From http://www.richelbilderbeek.nl/CppGetFilesInFolder.htm const std::vector<std::string> GetFilesInFolder(const std::string& folder) {   std::vector<std::string> v;   const boost::filesystem::path my_folder     = boost::filesystem::system_complete(         boost::filesystem::path(folder));   if (!boost::filesystem::is_directory(my_folder)) return v;   const boost::filesystem::directory_iterator j;   for ( boost::filesystem::directory_iterator i(my_folder);         i != j;         ++i)   {     if ( boost::filesystem::is_regular_file( i->status() ) )     {       const std::string filename = i->path().filename();       //const std::string full_filename = folder + "/" + filename;       v.push_back(filename);     }   }   return v; } //--------------------------------------------------------------------------- //From http://www.richelbilderbeek.nl/CppGetPath.htm const std::string GetPath(const std::string& filename) {   return boost::filesystem::path(filename).parent_path().string(); } //--------------------------------------------------------------------------- Dialog::Dialog(QWidget *parent) :     QDialog(parent),     ui(new Ui::Dialog) {   ui->setupUi(this);   const std::string my_name = QApplication::arguments()[0].toStdString();   this->setWindowTitle(my_name.c_str());   const std::vector<std::string> v = GetFilesInFolder(GetPath(my_name));   std::copy(v.begin(),v.end(),std::ostream_iterator<std::string>(std::cout,"\n"));   std::cout << "Number of files: " << v.size() << '\n';   BOOST_FOREACH(const std::string& s,v)   {     ui->text->appendHtml(s.c_str());   } } //--------------------------------------------------------------------------- Dialog::~Dialog() {   delete ui; } //--------------------------------------------------------------------------- void Dialog::changeEvent(QEvent *e) {   QDialog::changeEvent(e);   switch (e->type()) {   case QEvent::LanguageChange:     ui->retranslateUi(this);     break;   default:     break;   } } //---------------------------------------------------------------------------

 

 

 

 

 

dialog.h

 


#ifndef DIALOG_H #define DIALOG_H //--------------------------------------------------------------------------- #include <QDialog> //--------------------------------------------------------------------------- namespace Ui {   class Dialog; } //--------------------------------------------------------------------------- class Dialog : public QDialog {   Q_OBJECT public:   explicit Dialog(QWidget *parent = 0);   ~Dialog(); protected:   void changeEvent(QEvent *e); private:   Ui::Dialog *ui; }; //--------------------------------------------------------------------------- #endif // DIALOG_H

 

 

 

 

 

main.cpp

 


#include <QtGui/QApplication> #include "dialog.h" int main(int argc, char *argv[]) {     QApplication a(argc, argv);     Dialog w;     w.show();     return a.exec(); }

 

 

 

 

 

Process

 

Just running this project is known to cause the misc error [ui_dialog.h] Error 127.