Results 1 to 20 of 22

Thread: Lua into Qt

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,321
    Thanks
    316
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Lua into Qt

    If you are using Visual Studio for building your project, why are you also using Qt Creator? Stick with one or the other. I use Visual Studio (only) along with the Qt VS plugin for all of my Qt projects. The only thing I use Qt Creator for is to build and run the demos that come with Qt, and that only because I don't want to be bothered creating a Visual Studio project for them.

    Why are you putting LIB, DLL and EXE files into the VS project? What do you think Visual Studio (or Qt Creator for that matter) is going to do with them?

    By the way, if you are using Visual Studio to build your own project, any LIBs or DLLs also have to be built by the Visual C++ compiler. If your Qt Creator kit is using mingw, anything compiled in Qt Creator will be incompatible with code built in VS.

  2. #2
    Join Date
    Jun 2015
    Posts
    10
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Lua into Qt

    Im using Qt creator to adjust my .pro file, because I can launch qmake there (And I think that it's necessary for applying changes in .pro file). I couldn't find it in Visual Studio.

    I'm putting all files from the lua folder for 100% working. I will clean my project after it works.

    I downloaded lua5.3.0.tar.gz, opened Visual Studio command prompt and made the files with proper commands. Anyway it works in console project.

    I think the problem is in .pro file. I should link the lua library. How can I do it properly? (Maybe in Visual Studio, if it's possible)

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Lua into Qt

    Assuming your Lua deployment folder C:\Lua contains:
    Qt Code:
    1. Archive: lua-5.3_Win32_dll10_lib.zip
    2. Length Date Time Name
    3. --------- ---------- ----- ----
    4. 8433 10-30-2014 02:11 include/lauxlib.h
    5. 14734 12-27-2014 03:24 include/lua.h
    6. 191 12-23-2004 10:53 include/lua.hpp
    7. 20308 05-19-2015 11:04 include/luaconf.h
    8. 1173 02-07-2014 03:32 include/lualib.h
    9. 231936 05-20-2015 00:47 lua53.dll
    10. 30044 05-20-2015 00:47 lua53.lib
    11. --------- -------
    12. 306819 7 files
    To copy to clipboard, switch view to plain text mode 
    Then this does it
    Qt Code:
    1. TEMPLATE = app
    2. TARGET = test
    3. DEPENDPATH += .
    4. INCLUDEPATH += .
    5.  
    6. INCLUDEPATH += C:/Lua/include
    7. LIBS += -LC:/Lua -llua53
    8.  
    9. # Input
    10. SOURCES += main.cpp
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #include <QCoreApplication>
    2. #include <lua.hpp>
    3.  
    4. int main(int argc, char *argv[]) {
    5. QCoreApplication a(argc, argv);
    6. lua_State* s = luaL_newstate();
    7. luaopen_base(s);
    8. lua_pcall(s, 0, 0, 0);
    9.  
    10. int result = a.exec();
    11.  
    12. lua_close(s);
    13.  
    14. return result;
    15. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jun 2015
    Posts
    10
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Lua into Qt

    I couldn't find where I can use .pro file in Visual Studio (It creates .pro file, but then no using it).

    So I tried to do it with Qt Creator. Qt finds libraries,

    Qt Code:
    1. TEMPLATE = app
    2. TARGET = newluaQt
    3. DESTDIR = ../Win32/Debug
    4. QT += core widgets gui
    5. CONFIG += debug
    6. LIBS += -L"$$_PRO_FILE_PWD_/lua/" -llua5.3.0
    7. DEFINES += WIN64 QT_DLL QT_WIDGETS_LIB
    8. INCLUDEPATH += ./GeneratedFiles \
    9. . \
    10. ./GeneratedFiles/Debug \
    11. ./lua
    12. DEPENDPATH += .
    13. MOC_DIR += ./GeneratedFiles/debug
    14. OBJECTS_DIR += debug
    15. UI_DIR += ./GeneratedFiles
    16. RCC_DIR += ./GeneratedFiles
    17. include(newluaQt.pri)
    To copy to clipboard, switch view to plain text mode 

    How do i realise: I tried to launch with "-llua5.3" for example. And Qt said me "Can't find lua5.3 lib", then I tried "-llua5.3.0" and Qt said me again about my linker error. How can I fix it? I'm already trying to solve it by a couple of weeks

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Lua into Qt

    And Qt said me "Can't find lua5.3 lib", then I tried "-llua5.3.0" and Qt said me again about my linker error.
    Qt does not issue any of these messages. Your linker issues these messages because it was invoked with insufficient information to allow it to find the library. Once qmake has created the Makefile to your specification Qt is not involved in the process of compilation/linking.


    We cannot see what your library file is called or where it lives. Look at my example, work out the quite obvious pattern, and do the equivalent in your pro file.

    Is the name of your library file lua5.3.0.lib/lua5.3.0.dll? No, then adjust the pro file accordingly.
    Do you even have a compiled library to work with? I simply downloaded the precompiled library zip file to generate my example.
    Does your .lib file live in a directory called "lua" in the same place as the pro file? No, then adjust the pro file accordingly.
    Does _PRO_FILE_PWD_ expand to the value you think it does? Try an absolute path instead.
    Does newLuaQt.pri change any of these relevant variables?

    Try understanding the actual generated compiler command that fails and how that relates to your pro file.

  6. #6
    Join Date
    Jun 2015
    Posts
    10
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Lua into Qt

    We cannot see what your library file is called or where it lives
    I've written exactly what I have in the message above:
    What exactly I do now:
    Create Qt project in Visual stuido. Change x32 to x64 and check if the project launches correctly.
    After checking I add into the project folder (in the windows explorer) a new folder "lua" and put into this all necessary lua-files (lua .c, .h, one .hpp, .lib, .dll and .exe files). Then I create into solution explorer (in Visual Studio) a new folder "lua" and put (drag n drop) into this all files from the folder "lua" in the windows explorer.
    Then I attached a screenshot when you can see that the names are lua5.3.0.lib and lua5.3.0.dll: http://www.qtcentre.org/attachment.p...1&d=1434354607


    Do you even have a compiled library to work with?
    Yes, I've written it here:
    I downloaded lua5.3.0.tar.gz, opened Visual Studio command prompt and made the files with proper commands. Anyway it works in console project.

    Does your .lib file live in a directory called "lua" in the same place as the pro file?
    Yes, "I add into the project folder (in the windows explorer) [B]a new folder "lua" and put into this all necessary lua-files".
    The "project folder" I mean the directory of .pro file.


    Does _PRO_FILE_PWD_ expand to the value you think it does?
    Everyone writes that it's directory of .pro file. I have tried both $$_PRO_FILE_PWD_ and $$PWD. Okay, I will try the absolute.

    About .pri - Don't know. It's generated by Visual Studio

  7. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,321
    Thanks
    316
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Lua into Qt

    About .pri - Don't know. It's generated by Visual Studio
    It's generated by Visual Studio because you told it to.

    For some superstitious reason, you seem fixated on the idea that you must use both Visual Studio and Qt Creator to build your project. This mistaken idea is leading you down a road filled with confusing and conflicting assumptions about what you have to do to successfully configure your project. If you are trying to work in both environments simultaneously, it is no wonder your projects are an unbuildable mess.

    If you are more familiar with Visual Studio, use Visual Studio only and forget about Qt Creator.

    If you are more familiar with Qt Creator, use Qt Creator only and forget about Visual Studio.

    If you don't know either one, then pick one of the two, learn it, and stick with it. Forget about the other one. You can use the same toolchain (Visual C++ compilers and linkers) with either development environment. The compilers and linkers are not the same as Visual Studio, they are external programs used by Visual Studio to build projects. Any development environment, including Qt Creator, can be configured to use the same toolchain that Visual Studio does to produce executable programs that are identical in all respects.

    The Qt plugin for Visual Studio is simply a tool to help you create and edit Qt-based projects from inside of Visual Studio. Yes, it does offer a feature to create a .pro file, but this is totally unnecessary for creating and building Qt projects using Visual Studio. It is a convenience for creating a .pro file that you can use if you want to move the project out of Visual Studio and into another build environment, like Qt Creator on a Unix box. The plugin also offers a tool to import .pro files into a Visual Studio project, in case you are moving from a different environment and want to use VS instead.

    Others here have shown you that they can build a QApplication-based Qt project that links to and executes lua code. Several posts ago, ChrisW67 posted both C++ code and a Qt .pro file that does exactly that.

    You can use that example exactly as written in Qt Creator to build the same project, assuming you have the same directory layout as he also showed.

    You can also import that .pro file into Visual Studio (and then forget the .pro file exists, because you'll be using the .vcproj (or .vcxproj, depending on VS version) from then on.

    So pick one or the other as your development environment, forget about the one you don't pick, and move on. You are making it much harder than it really is.

  8. #8
    Join Date
    Jun 2015
    Posts
    10
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Lua into Qt

    okay, in other words if I have such .pri file:

    HEADERS += ./lua/lauxlib.h \
    ./lua/lua.h \
    ./lua/lua.hpp \
    ./lua/luaconf.h \
    ./lua/lualib.h \
    ./newluaqt.h
    SOURCES += ./main.cpp \
    ./newluaqt.cpp
    FORMS += ./newluaqt.ui
    RESOURCES += newluaqt.qrc
    DEPENDPATH += .
    INCLUDEPATH += .
    INCLUDEPATH += C:/Lua
    LIBS += -LC:/Lua -llua53
    I can click "import .pri file" and everything will be ok?
    No. C:/Lua - there's lua53.dll and lua53.lib and the rest. And again the linker error...

    Maybe somebody can upload working project? I have just tried all that I can. I tried to follow every advise, but they weren't work. I dont know why it is so

  9. #9
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Lua into Qt

    Try to break down the problem into smaller ones:
    1. Get some project to compile and link with Lua. In order to do that, just pick ChrisW67's minimal example, and build it like you do usually, e.g. with qmake and make.
    2. Get some project to compile and link with Lua within Visual Studio. Import ChrisW67's minimal example in Visual Studio and try to build it.
    3. Get your own project to compile and link with Lua within Visual Studio. One possibility is to start with ChrisW67's minimal example and edit the .pro file. I can already see two potential issues with your last attempt: you wrote a .pri file, unlike ChrisW67 who wrote a .pro file. You forgot the TEMPLATE and TARGET clauses in your project file.

    How far you get on this list will hint at the root cause of your problem. And remember: when someone posts a minimal, working solution, please at least try it to rule out installation/configuration/PEBKAC causes. Ignoring valuable input will not get you anywhere on this forum.

  10. The following user says thank you to yeye_olive for this useful post:

    d_stranz (18th June 2015)

  11. #10
    Join Date
    Jun 2015
    Posts
    10
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Lua into Qt

    I haven't seen any working solution

  12. #11
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Lua into Qt

    Quote Originally Posted by Defake View Post
    I haven't seen any working solution
    Well, I haven't seen anyone doing my work for me either. Right now you have not told us anything about ChrisW67's minimal example. We are left to wonder in which of the following situations you are:
    • you have not bothered trying to import and build it, because you had rather let others take over and magically post a working version of your project, even if they do not have access to its sources and your particular configuration;
    • you have tried to import and build it, but it failed with some error message only you know about;
    • you have successfully imported and built it, but the same cannot be told of your project, due to some difference only you may know about.

    I understand how frustrating it can be to be stalled by such a problem, but please do not confuse this forum with commercial support. People are willing to help you, but you have to show interest in working out a solution with all the advice they provide. Do yourself a service and start interacting with them.

  13. #12
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,321
    Thanks
    316
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Lua into Qt

    I haven't seen any working solution
    I refer you to ChrisW67's post #11 in this thread.

    What more do you need? It's a complete example. Copy the code, paste it into files on your PC, make sure your Lua directory matches his, load the .pro file either into Qt Creator (directly) or into Visual Studio (using the Qt VS plugin import capability), compile it, and run it. If you can do that minimal thing (without once again trying to roll your own solution before trying this first), then go to work on modifying that example to do what you actually need to do.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.