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. MT4 Manager API on QT

MT4 Manager API on QT

Scheduled Pinned Locked Moved Unsolved General and Desktop
socketc++mfc
5 Posts 3 Posters 433 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.
  • B Offline
    B Offline
    Blustack3r
    wrote on 26 Jun 2024, 08:12 last edited by Blustack3r
    #1

    Hello Everyone,

    I am new on QT and i was trying if i can use MT4 Manager API on QT since i want to improve the apps that i have created on MFC (c++). Was able to load the manager interface but i can't connect the manager to the server. Below are the code that i have on C++

    .h

    if (!AfxSocketInit())
    {
    	AfxMessageBox("Socket initialization failed.");
    	return FALSE;
    }
    
    if (m_factory.IsValid() == FALSE || (m_manager = m_factory.Create(ManAPIVersion)) == NULL || (m_pump = m_factory.Create(ManAPIVersion)) == NULL)
    {
    	AfxMessageBox("Failed to create manager interface.");
    	return FALSE;
    }
    

    .cpp

    int res = -1;
    
    res = m_manager->Connect("access.metatrader5.com:443");
    if (res != RET_OK)
    	MessageBox("Server connection failed.");
    
    

    And on QT which i have based the initialization of the socket using QTcpSocket.

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QMessageBox>
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        connect(ui->pushButton, &QPushButton::clicked, this, &MainWindow::on_connect);
    
    
        socket = new QTcpSocket(this);
        if(!socket)
            QMessageBox::critical(this, "Socket initialization Failed", "Failed to create socket");
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
        if(m_manager)
        {
            m_manager->Release();
        }
    }
    
    void MainWindow::on_connect()
    {
        int res =-1;
        QMessageBox msgbox;
    
    
        if(m_factory.IsValid()== FALSE || (m_manager = m_factory.Create(ManAPIVersion)) == NULL)
        {
            msgbox.setText("m_factory is invalid.");
            msgbox.exec();
        }
        else
        {
           
    
            res = m_manager->Connect("access.metatrader5.com:443");
            if(res != RET_OK)
            {
                msgbox.setText(m_manager->ErrorDescription(res));
                msgbox.exec();
            }
        }
    }
    

    On MFC, i just initialize the socket (AfxSocketInit()) to connect using m_manager->connect("access.metaquotes.net:443") and was able to connect.

    I hope you can help me on how to properly connect using socket on QT.

    Thanks

    J 1 Reply Last reply 26 Jun 2024, 08:22
    0
    • B Blustack3r
      26 Jun 2024, 08:12

      Hello Everyone,

      I am new on QT and i was trying if i can use MT4 Manager API on QT since i want to improve the apps that i have created on MFC (c++). Was able to load the manager interface but i can't connect the manager to the server. Below are the code that i have on C++

      .h

      if (!AfxSocketInit())
      {
      	AfxMessageBox("Socket initialization failed.");
      	return FALSE;
      }
      
      if (m_factory.IsValid() == FALSE || (m_manager = m_factory.Create(ManAPIVersion)) == NULL || (m_pump = m_factory.Create(ManAPIVersion)) == NULL)
      {
      	AfxMessageBox("Failed to create manager interface.");
      	return FALSE;
      }
      

      .cpp

      int res = -1;
      
      res = m_manager->Connect("access.metatrader5.com:443");
      if (res != RET_OK)
      	MessageBox("Server connection failed.");
      
      

      And on QT which i have based the initialization of the socket using QTcpSocket.

      #include "mainwindow.h"
      #include "ui_mainwindow.h"
      #include <QMessageBox>
      
      MainWindow::MainWindow(QWidget *parent)
          : QMainWindow(parent)
          , ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
          connect(ui->pushButton, &QPushButton::clicked, this, &MainWindow::on_connect);
      
      
          socket = new QTcpSocket(this);
          if(!socket)
              QMessageBox::critical(this, "Socket initialization Failed", "Failed to create socket");
      }
      
      MainWindow::~MainWindow()
      {
          delete ui;
          if(m_manager)
          {
              m_manager->Release();
          }
      }
      
      void MainWindow::on_connect()
      {
          int res =-1;
          QMessageBox msgbox;
      
      
          if(m_factory.IsValid()== FALSE || (m_manager = m_factory.Create(ManAPIVersion)) == NULL)
          {
              msgbox.setText("m_factory is invalid.");
              msgbox.exec();
          }
          else
          {
             
      
              res = m_manager->Connect("access.metatrader5.com:443");
              if(res != RET_OK)
              {
                  msgbox.setText(m_manager->ErrorDescription(res));
                  msgbox.exec();
              }
          }
      }
      

      On MFC, i just initialize the socket (AfxSocketInit()) to connect using m_manager->connect("access.metaquotes.net:443") and was able to connect.

      I hope you can help me on how to properly connect using socket on QT.

      Thanks

      J Offline
      J Offline
      JonB
      wrote on 26 Jun 2024, 08:22 last edited by
      #2

      @Blustack3r said in MT4 Manager API on QT:

      I hope you can help me on how to properly connect using socket on QT.

      Did you try QAbstractSocket::connectToHost()?

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Blustack3r
        wrote on 26 Jun 2024, 11:06 last edited by
        #3

        Hi,

        The only thing is that, if you check the C++ code, you will just need to initialize the socket. The way i see it on QT, you will need to "connect" the socket to the IP address of which if you will check again on the C++ code, the "m_manager" already has the function "connect"

        Pl45m4P 1 Reply Last reply 26 Jun 2024, 12:12
        0
        • B Blustack3r
          26 Jun 2024, 11:06

          Hi,

          The only thing is that, if you check the C++ code, you will just need to initialize the socket. The way i see it on QT, you will need to "connect" the socket to the IP address of which if you will check again on the C++ code, the "m_manager" already has the function "connect"

          Pl45m4P Online
          Pl45m4P Online
          Pl45m4
          wrote on 26 Jun 2024, 12:12 last edited by Pl45m4
          #4

          @Blustack3r said in MT4 Manager API on QT:

          The only thing is that, if you check the C++ code, you will just need to initialize the socket.

          Currently your QTcpSocket does nothing. You create it here

          socket = new QTcpSocket(this);
          

          and then never use it, AFAICS.

          The way i see it on QT, you will need to "connect" the socket to the IP address of which if you will check again on the C++ code, the "m_manager" already has the function "connect"

          I don't know what MT4 Manager does or how it works.
          If you want to use QTcpSocket you need to use the QTcpSocket API to connect to some host.
          (like @JonB said above)
          However:
          Since the MT4 API is probably incompatible with QTcpSocket by default and you probably need to use the Manager's connect function to make everything that is going on in the background work properly, I don't see why you need to use the Qt socket classes, assuming this MT4 Manager has its own internal socket stuff?!
          I could be wrong, though.

          Just check/compare your code with this
          (dont even know if this is the API you are using)

          • https://github.com/tyolab/MT4-Manager-API-1/blob/master/Examples/ManagerAPIAdmin/ManagerAPITestDlg.cpp#L249

          Edit:

          Only because you have Qt in your app, you are not forced to use the Q-classes everywhere.
          You still have a "regular" C++ app and as long as you can't (or don't want to) wrap around this MT4 Manager, I think life is easier when doing it the recommended (MT4-) way. Just be careful not to block the Qt event loop and queue and you are good to go.


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          B 1 Reply Last reply 27 Jun 2024, 02:58
          0
          • Pl45m4P Pl45m4
            26 Jun 2024, 12:12

            @Blustack3r said in MT4 Manager API on QT:

            The only thing is that, if you check the C++ code, you will just need to initialize the socket.

            Currently your QTcpSocket does nothing. You create it here

            socket = new QTcpSocket(this);
            

            and then never use it, AFAICS.

            The way i see it on QT, you will need to "connect" the socket to the IP address of which if you will check again on the C++ code, the "m_manager" already has the function "connect"

            I don't know what MT4 Manager does or how it works.
            If you want to use QTcpSocket you need to use the QTcpSocket API to connect to some host.
            (like @JonB said above)
            However:
            Since the MT4 API is probably incompatible with QTcpSocket by default and you probably need to use the Manager's connect function to make everything that is going on in the background work properly, I don't see why you need to use the Qt socket classes, assuming this MT4 Manager has its own internal socket stuff?!
            I could be wrong, though.

            Just check/compare your code with this
            (dont even know if this is the API you are using)

            • https://github.com/tyolab/MT4-Manager-API-1/blob/master/Examples/ManagerAPIAdmin/ManagerAPITestDlg.cpp#L249

            Edit:

            Only because you have Qt in your app, you are not forced to use the Q-classes everywhere.
            You still have a "regular" C++ app and as long as you can't (or don't want to) wrap around this MT4 Manager, I think life is easier when doing it the recommended (MT4-) way. Just be careful not to block the Qt event loop and queue and you are good to go.

            B Offline
            B Offline
            Blustack3r
            wrote on 27 Jun 2024, 02:58 last edited by
            #5

            Hi.

            Thank you for the explanation.

            @Pl45m4 said in MT4 Manager API on QT:

            Since the MT4 API is probably incompatible with QTcpSocket by default and you probably need to use the Manager's connect function to make everything that is going on in the background work properly, I don't see why you need to use the Qt socket classes, assuming this MT4 Manager has its own internal socket stuff?!
            I could be wrong, though.

            Yes this is correct. The only thing is that, when i use the MT4 Manager to connect to the server, it always returns "no connection" error, which means, the MT4 Manager can't establish connection to the server, of which the server is online and i have run the C++ program with the same server credentials.

            1 Reply Last reply
            0

            1/5

            26 Jun 2024, 08:12

            • Login

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