Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Windows to Linux
Qt 6.11 is out! See what's new in the release blog

Windows to Linux

Scheduled Pinned Locked Moved General and Desktop
7 Posts 6 Posters 3.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TZHF
    wrote on last edited by
    #1

    I've done various assignments on Qt Creator on Windows but have recently been told they must compile in Linux which they do not. Is there any general fix so that I can get them to compile and run on Linux machines at University. Since they are University machines I obviously cant install any software in order to so. I've tried the obvious stuff like making new files in Linux and copying the content over but this doesn't work. Below is a copy of one of the assignments. Any help would be appreciated. Thanks in advance.

    paintWidget.h
    @#ifndef PAINT_WIDGET
    #define PAINT_WIDGET

    #include <QWidget>
    #include <QtGui>

    //maximum amount of points that can be painted
    #define PIXEL_POINTS 100000
    //These two set the boundary of what can be painted on as the origins of the images
    #define PAGE_WIDTH 0
    #define PAGE_HEIGHT 0

    //Class
    class paintWidget : public QWidget
    {
    Q_OBJECT

    public:
    //model

    paintWidget(QWidget* parent = 0);
    QImage *theImage = new QImage(10000, 10000, QImage::Format_RGB32);
    //routines
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void paintEvent(QPaintEvent *event);
    

    private:
    //variables needed for routines
    int gx[PIXEL_POINTS], gy[PIXEL_POINTS];
    int gi;
    };
    #endif // PAINT_WIDGET@

    paintWidget.cpp
    @#include <QtGui>
    #include "paintWidget.h"

    paintWidget::paintWidget(QWidget *parent):
    QWidget(parent)
    {
    gi=0;
    //set the image to white
    QColor whiteColour(255, 255, 255);
    theImage->fill(whiteColour.rgba());

    }

    void paintWidget::paintEvent(QPaintEvent *event)
    {
    QPainter painter(this);
    //set image to screen
    QPointF imageOrigin(0.0, 0.0);
    painter.drawImage(imageOrigin, *theImage);
    int i;
    //sets the pointer to black
    painter.setPen(QPen(Qt::black, 5 ));
    for ( i = 0 ; i < gi-1 ; ++ i ){
    if ( gy[i] > PAGE_WIDTH + PAGE_HEIGHT )
    painter.drawPoint(QPointF( gx[i], gy[i]));

    }
    }
    void paintWidget::mouseMoveEvent( QMouseEvent *event){
    gx[gi] = (event->x());
    gy[gi] = (event->y());
    if ( gi < PIXEL_POINTS - 1)
    ++gi;
    repaint();
    }
    void paintWidget::mousePressEvent(QMouseEvent *event) {
    gx[gi] = (event->x());
    gy[gi] = (event->y());

    }@
    main.cpp
    @#include "paintWidget.h"
    #include <QApplication>

    int main(int argc, char *argv[])
    {
    //create the application, set the window size and set the window to show.
    QApplication app(argc, argv);
    paintWidget g;
    g.resize(500, 400);
    g.show();

    //event loop
    return app.exec&#40;&#41;;
    

    }
    @

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sptrakesh
      wrote on last edited by
      #2

      If your linux machines do not have Qt installed (which I assume is why your code does not compile on Linux), your only option is to install them to your home directory or other location that you have write access to. In any case, without describing the errors you get on Linux it would be hard for anyone to offer proper advice.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DerManu
        wrote on last edited by
        #3

        Not sure that installing Qt in your home directory would fix anything, because it has to compile on the machine your tutor/lecturer uses to compile your assignments. And if you can't convince him that installing the Qt dev package is good, you'll have to do your assignments without Qt. That shouldn't be a problem though, because then the assignments are obviously doable without help of Qt.

        1 Reply Last reply
        0
        • musimbateM Offline
          musimbateM Offline
          musimbate
          wrote on last edited by
          #4

          As they have mentioned Qt must be installed on the machine.Also what compiler were used on the windows machine?Some settings are compiler specific and don't work when you get it wrong.You might want to look into that too.This has burned me recently.
          Good luck.

          Why join the navy if you can be a pirate?-Steve Jobs

          1 Reply Last reply
          0
          • sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #5

            You can compile Qt locally without installing, too. But best option would be to convince people that installing Qt is a good idea.

            Or you can compile the project on your PC and then deploy it on University machines without installing Qt.

            (Z(:^

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Achab
              wrote on last edited by
              #6

              It is not a problem of Linux or Windows. In fact I have been able to compile your code in Linux. The problem is the C++ 98 standard that do not let initialize non static data members in header. In fact only int statics can be initialized. To avoid problems initialize theImage in the constructor.

              1 Reply Last reply
              0
              • T Offline
                T Offline
                TZHF
                wrote on last edited by
                #7

                Thanks for all the replies. For all the people wondering if QT is installed on the Linux machines, it definitely is because everyone else seems to be able to compile and run their code and most people have done these assignments at University on the same Linux machines. Achab I had a feeling that was the problem since windows was compiling and running but giving me a warning about non static data members, I will do what you have suggested and hopefully it shall work. Once again thanks for your help, you have been more helpful then my lecturer who basically just told me to sort it out myself without any hints or advice.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved