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. Add Prolog in a Qt application

Add Prolog in a Qt application

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.9k 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.
  • A Offline
    A Offline
    Amott
    wrote on 22 Mar 2017, 17:46 last edited by
    #1

    Hello everyone,

    I need to add an AI in my application and to do that, I decided to work with Prolog.
    I downloaded SWI-Prolog here (32bit version, as I build my project with Qt 5.8 MinGW 32bit), and I installed it.

    Then I added the libswipl.lib to my project (right clic / Add library on QtCreator), here is what my .pro looks like :

    #-------------------------------------------------
    #
    # Project created by QtCreator 2017-03-19T17:55:04
    #
    #-------------------------------------------------
    
    QT       += core gui
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    TARGET = TestProlog
    TEMPLATE = app
    
    SOURCES += main.cpp
    
    win32: LIBS += -L$$PWD/'../../../../../Program Files (x86)/swipl/lib/' -llibswipl
    
    INCLUDEPATH += $$PWD/'../../../../../Program Files (x86)/swipl/include'
    DEPENDPATH += $$PWD/'../../../../../Program Files (x86)/swipl/include'
    
    win32:!win32-g++: PRE_TARGETDEPS += $$PWD/'../../../../../Program Files (x86)/swipl/lib/libswipl.lib'
    
    
    

    After that, I wanted to test if everything is ok, so I took an example on the internet, here is my main.cpp :

    #include <QApplication>
    #include <QInputDialog>
    #include <QMessageBox>
    
    #include <SWI-Prolog.h>
    #include <SWI-cpp.h>
    #include <SWI-Stream.h>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
        PlEngine e(argc, argv);
        QString pal = QInputDialog::getText(0, "Palindrome check", "enter text");
        PlTerm ATOM = PlAtom(qPrintable(pal.toUtf8())), LIST;
        PlCall("atom_codes", PlTermv(ATOM, LIST));
        if (PlCall("reverse", PlTermv(LIST, LIST)))
            QMessageBox::information(0, "outcome", "is a palindrome");
        else
            QMessageBox::information(0, "outcome", "is NOT a palindrome");
    
        return 0;
    }
    
    

    It successfully build, but when I run the application, it crashes immediately. I tried to debug it by setting a break point on the first line and and error ocurred "During startup program exited with code 0xc0000135".
    If I comment Prolog related lines, the application runs normally.

    What am I doing wrong ? Did I missed something ?

    Thanks in advance for your help, have a good day !

    E 1 Reply Last reply 22 Mar 2017, 22:08
    0
    • A Amott
      22 Mar 2017, 17:46

      Hello everyone,

      I need to add an AI in my application and to do that, I decided to work with Prolog.
      I downloaded SWI-Prolog here (32bit version, as I build my project with Qt 5.8 MinGW 32bit), and I installed it.

      Then I added the libswipl.lib to my project (right clic / Add library on QtCreator), here is what my .pro looks like :

      #-------------------------------------------------
      #
      # Project created by QtCreator 2017-03-19T17:55:04
      #
      #-------------------------------------------------
      
      QT       += core gui
      
      greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
      
      TARGET = TestProlog
      TEMPLATE = app
      
      SOURCES += main.cpp
      
      win32: LIBS += -L$$PWD/'../../../../../Program Files (x86)/swipl/lib/' -llibswipl
      
      INCLUDEPATH += $$PWD/'../../../../../Program Files (x86)/swipl/include'
      DEPENDPATH += $$PWD/'../../../../../Program Files (x86)/swipl/include'
      
      win32:!win32-g++: PRE_TARGETDEPS += $$PWD/'../../../../../Program Files (x86)/swipl/lib/libswipl.lib'
      
      
      

      After that, I wanted to test if everything is ok, so I took an example on the internet, here is my main.cpp :

      #include <QApplication>
      #include <QInputDialog>
      #include <QMessageBox>
      
      #include <SWI-Prolog.h>
      #include <SWI-cpp.h>
      #include <SWI-Stream.h>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
      
          PlEngine e(argc, argv);
          QString pal = QInputDialog::getText(0, "Palindrome check", "enter text");
          PlTerm ATOM = PlAtom(qPrintable(pal.toUtf8())), LIST;
          PlCall("atom_codes", PlTermv(ATOM, LIST));
          if (PlCall("reverse", PlTermv(LIST, LIST)))
              QMessageBox::information(0, "outcome", "is a palindrome");
          else
              QMessageBox::information(0, "outcome", "is NOT a palindrome");
      
          return 0;
      }
      
      

      It successfully build, but when I run the application, it crashes immediately. I tried to debug it by setting a break point on the first line and and error ocurred "During startup program exited with code 0xc0000135".
      If I comment Prolog related lines, the application runs normally.

      What am I doing wrong ? Did I missed something ?

      Thanks in advance for your help, have a good day !

      E Offline
      E Offline
      Eeli K
      wrote on 22 Mar 2017, 22:08 last edited by
      #2

      @Amott You are probably missing some .dll library. I don't know which one. Try http://www.dependencywalker.com/.

      1 Reply Last reply
      2
      • A Offline
        A Offline
        Amott
        wrote on 23 Mar 2017, 00:10 last edited by
        #3

        Thanks Eeli K, you were right !
        I needed to put 2 DLLs from Prolog into my directory (libswipl.dll and libgmp-10.dll) !
        Thanks a lot !

        1 Reply Last reply
        0

        2/3

        22 Mar 2017, 22:08

        • Login

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