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. How to use object of one class in another one
Forum Updated to NodeBB v4.3 + New Features

How to use object of one class in another one

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 634 Views
  • 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.
  • R Offline
    R Offline
    rezaMSLM
    wrote on last edited by
    #1

    in my project I have two classes: "MainWindow" and "secwindow"
    my MainWindow.h:

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include <QtNetwork/QFtp>
    #include "secwindow.h"
    namespace Ui {
    class MainWindow;
    }
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit MainWindow(QWidget *parent = 0);
       
        ~MainWindow();
    
    private slots:
    .
    .
    .
    private:
        Ui::MainWindow *ui;
        SecWindow *secWindow;
        QFtp *ftp;
        .
       .
    
    };
    
    #endif // MAINWINDOW_H
    

    my secwindow.h:

    #ifndef SECWINDOW_H
    #define SECWINDOW_H
    
    #include <QDialog>
    #include <QFile>
    //#include "mainwindow.h"
    namespace Ui {
    class SecWindow;
    }
    
    class SecWindow : public QDialog
    {
        Q_OBJECT
    
    public:
        explicit SecWindow(QWidget *parent = 0);
        ~SecWindow();
    
    private slots:
        void on_pushButton_write_values_clicked();
    
    private:
        Ui::SecWindow *ui;
        QFile *myfile;
        QString s1,s2,s3,s4,s5,s6,s7,s8,s9;
    
    };
    
    #endif // SECWINDOW_H
    

    How I can use "ftp" in secwindow?

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      This question has been asked a million times.
      You don't use it.
      SecWindow should emit a signal, MainWindow will pick up the signal and use ftp.

      P.S.
      If you are using Qt5 avoid QFtp. It's unsupported and outdated

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      5
      • TheTugaOneT Offline
        TheTugaOneT Offline
        TheTugaOne
        wrote on last edited by
        #3

        You question "How I can use "ftp" in secwindow?" is rather vague. Depending on your needs you can use pointers or references to pass the "ftp" object to "SecWindow" . If you don't need a reference to the object you can definitely take a look at VRonin's answer in more detail here http://doc.qt.io/archives/qt-4.8/signalsandslots.html .

        1 Reply Last reply
        1

        • Login

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