Same Qt project compiles on Windows but it doesn't compile on Linux



  • Hi guys! I'm new here in Qt Forum.

    I have a weird problem, the same project compiles (and runs) on Windows but it doesn't compile on Linux. Following is a piece of code, the compile output and involved classes:

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QMessageBox>
    #include <QFileDialog>
    #include <QTreeView>
    #include <QListView>
    #include <QStringListModel>
    #include <QDebug>
    #include <QModelIndexList>
    #include <QString>
    #include <QFileDialog>

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    collectionClient(QString::fromStdString("http://localhost:8084/irods-rest/rest/collection/"), this),
    fileClient(QString::fromStdString("http://localhost:8084/irods-rest/rest/fileContents/"), this),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    updateModel();
    

    }
    [.............]

    Compíle output:

    home/junior/Qt/5.4/gcc_64/bin/uic ../irods_client/mainwindow.ui -o ui_mainwindow.h
    g++ -c -pipe -g -Wall -W -D_REENTRANT -fPIE -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I/home/junior/Qt/5.4/gcc_64/mkspecs/linux-g++ -I../irods_client -I/home/junior/Qt/5.4/gcc_64/include -I/home/junior/Qt/5.4/gcc_64/include/QtWidgets -I/home/junior/Qt/5.4/gcc_64/include/QtGui -I/home/junior/Qt/5.4/gcc_64/include/QtNetwork -I/home/junior/Qt/5.4/gcc_64/include/QtCore -I. -I. -I. -o main.o ../irods_client/main.cpp
    g++ -c -pipe -g -Wall -W -D_REENTRANT -fPIE -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I/home/junior/Qt/5.4/gcc_64/mkspecs/linux-g++ -I../irods_client -I/home/junior/Qt/5.4/gcc_64/include -I/home/junior/Qt/5.4/gcc_64/include/QtWidgets -I/home/junior/Qt/5.4/gcc_64/include/QtGui -I/home/junior/Qt/5.4/gcc_64/include/QtNetwork -I/home/junior/Qt/5.4/gcc_64/include/QtCore -I. -I. -I. -o mainwindow.o ../irods_client/mainwindow.cpp
    In file included from ../irods_client/mainwindow.cpp:1:0:
    ../irods_client/mainwindow.h: In constructor 'MainWindow::MainWindow(QWidget*)':
    ../irods_client/mainwindow.h:38:24: warning: 'MainWindow::fileClient' will be initialized after [-Wreorder]
    FileContentsClient fileClient;
    ^
    ../irods_client/mainwindow.h:35:21: warning: 'Ui::MainWindow* MainWindow::ui' [-Wreorder]
    Ui::MainWindow ui;
    ^
    ../irods_client/mainwindow.cpp:13:1: warning: when initialized here [-Wreorder]
    MainWindow::MainWindow(QWidget parent) :
    ^
    ../irods_client/mainwindow.cpp:17:26: error: no matching function for call to 'CollectionClient::CollectionClient(QString, MainWindow
    const)'
    ui(new Ui::MainWindow)
    ^
    ../irods_client/mainwindow.cpp:17:26: note: candidates are:
    In file included from ../irods_client/mainwindow.h:7:0,
    from ../irods_client/mainwindow.cpp:1:
    ../irods_client/collectionclient.h:11:14: note: CollectionClient::CollectionClient(QString&, QObject
    )
    explicit CollectionClient(QString &baseURL, QObject parent = 0);
    ^
    ../irods_client/collectionclient.h:11:14: note: no known conversion for argument 1 from 'QString' to 'QString&'
    ../irods_client/collectionclient.h:7:7: note: CollectionClient::CollectionClient(const CollectionClient&)
    class CollectionClient: public AbstractHTTPClient
    ^
    ../irods_client/collectionclient.h:7:7: note: candidate expects 1 argument, 2 provided
    ../irods_client/mainwindow.cpp:17:26: error: no matching function for call to 'FileContentsClient::FileContentsClient(QString, MainWindow
    const)'
    ui(new Ui::MainWindow)
    ^
    ../irods_client/mainwindow.cpp:17:26: note: candidates are:
    In file included from ../irods_client/mainwindow.h:8:0,
    from ../irods_client/mainwindow.cpp:1:
    ../irods_client/filecontentsclient.h:12:14: note: FileContentsClient::FileContentsClient(QString&, QObject*)
    explicit FileContentsClient(QString &baseURL, QObject *parent = 0);
    ^
    ../irods_client/filecontentsclient.h:12:14: note: no known conversion for argument 1 from 'QString' to 'QString&'
    ../irods_client/filecontentsclient.h:8:7: note: FileContentsClient::FileContentsClient(const FileContentsClient&)
    class FileContentsClient: public AbstractHTTPClient
    ^
    ../irods_client/filecontentsclient.h:8:7: note: candidate expects 1 argument, 2 provided
    ../irods_client/mainwindow.cpp: In member function 'void MainWindow::updateModel()':
    ../irods_client/mainwindow.cpp:51:103: error: no matching function for call to 'CollectionClient::getCollectionData(QString)'
    QStringList list = collectionClient.getCollectionData(QString::fromStdString("tempZone/home/rods"));
    ^
    ../irods_client/mainwindow.cpp:51:103: note: candidate is:
    In file included from ../irods_client/mainwindow.h:7:0,
    from ../irods_client/mainwindow.cpp:1:
    ../irods_client/collectionclient.h:13:17: note: QStringList CollectionClient::getCollectionData(QString&)
    QStringList getCollectionData(QString &path);
    ^
    ../irods_client/collectionclient.h:13:17: note: no known conversion for argument 1 from 'QString' to 'QString&'
    make: *** [mainwindow.o] Error 1
    16:18:20: The process "/usr/bin/make" exited with code 2.
    Error while building/deploying project irods_client (kit: Desktop Qt 5.4.0 GCC 64bit)
    When executing step "Make"

    -Constructor from FileContentsClient:
    Header:
    class FileContentsClient: public AbstractHTTPClient
    {
    Q_OBJECT
    public:
    explicit FileContentsClient(QString &baseURL, QObject *parent = 0);

    [............]

    CPP:
    FileContentsClient::FileContentsClient(QString &bURL, QObject parent) :
    AbstractHTTPClient(bURL, parent)
    {
    connect(&manager, SIGNAL(finished(QNetworkReply
    )),
    this, SLOT(replyFinished(QNetworkReply*)));

    }

    I know that the compiler points to some errors on this code, but, why the SAME code compiles without problems on Windows?
    Project tree: https://dl.dropboxusercontent.com/u/16292723/qt_probs.png



  • Hi,

    the ordering warning means that you're creating members in a different order that the one you used to declare them in header.
    Example:

    MyClass.h

    class MyClass
    {
    ...
    private:
      int a;
      std::string b;
    };
    

    MyClass.cpp

    MyClass::MyClass()
      : b("hello world")
      , a(3) {}
    

    The error is because you're passing a temporary string as reference. Compilers implements in different ways some checks but IMO your code is wrong. You should use const reference

    class FileContentsClient: public AbstractHTTPClient
    {
      Q_OBJECT
    public:
      explicit FileContentsClient(const QString &baseURL, QObject *parent = 0);
    ...
    };
    

  • Lifetime Qt Champion

    Hi,

    To add to @mcosta

    collectionClient(QString::fromStdString("http://localhost:8084/irods-rest/rest/collection/")

    can be greatly simplified

    collectionClient(QStringLiteral("http://localhost:8084/irods-rest/rest/collection/"),


  • Moderators

    @SGaist said:

    collectionClient(QString::fromStdString("http://localhost:8084/irods-rest/rest/collection/"))

    can be greatly simplified

    collectionClient(QStringLiteral("http://localhost:8084/irods-rest/rest/collection/"))

    ...or even collectionClient("http://localhost:8084/irods-rest/rest/collection/") :) (but QStringLiteral is a tiny tiny bit faster)



  • Guys, thanks for your help. Me and my colleagues are working to repair that problems.

    Besides the error on code, it is very strange the fact by which Microsoft Visual C++ Compiler accepts and build the code with those errors. Compiler on Linux does not accept this.


  • Lifetime Qt Champion

    Hi,

    Not all compilers are picky the same way. They implement the standard but some of its clauses give freedom to the implementer. That's why it's always nice to try building on several platforms, sometimes it helps catch strange little things.



  • To add to @SGaist:

    In my company we build the same code in 3 platform

    • Windows / Visual C++
    • Linux / g++
    • OSX / clang

    Usually Visual C++ is the one less conform to the standard


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.