Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6138193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:49:13+00:00 2026-05-23T17:49:13+00:00

i have written a library with some classes that make use of qt object

  • 0

i have written a library with some classes that make use of qt object such as QVector, QColor etc, without inheriting from them. Now I would like to make these objects (partially) available to python. I first tried SIP, but this is so poorly documented that I can’t even build the example. Now I am trying boost.python, which works fine for standard c++ classes.

However, once I start to include Qt stuff, it still compiles, but fails to import to python. Here is a minimal example:

testclass.h

#include <QDebug>
#include <QVector>
#include <QColor>

class testclass
{
public:
    testclass();
    const char* output();
    QVector<double> & data();
    static int x(){return 1;}
    QColor * c();

private:
    QVector<double> v;
};
struct stat;

testclass.cpp

#include "testclass.h"

testclass::testclass()
{

}

const char* testclass::output()
{
    qDebug() << "string";
    return "hello";
}

QVector< double >& testclass::data()
{
    return v;
}

QColor* testclass::c()
{
    return new QColor();
}

testclassBoost.cpp

#include "testclass.h"
#include <boost/python.hpp>

using namespace boost::python;

BOOST_PYTHON_MODULE(libtestclass)
{
    // Create the Python type object for our extension class and define __init__ function.
    class_<testclass>("testclass", init<>())
    .def("output", &testclass::output)  // Add a regular member function.
    ;
}

CMakeList.txt

project(boostpythontest)
cmake_minimum_required(VERSION 2.8)
find_package(Qt4 REQUIRED)

FIND_PACKAGE(Boost 1.45.0)
IF(Boost_FOUND)
  SET(Boost_USE_STATIC_LIBS OFF)
  SET(Boost_USE_MULTITHREADED ON)
  SET(Boost_USE_STATIC_RUNTIME OFF)
  FIND_PACKAGE(Boost 1.45.0 COMPONENTS python)
ELSEIF(NOT Boost_FOUND)
  MESSAGE(FATAL_ERROR "Unable to find correct Boost version. Did you set BOOST_ROOT?")
ENDIF()

include_directories(${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR} ${Boost_INCLUDE_DIRS} "/usr/include/python2.7")


set(SRCS
  testclass.cpp
  testclassBoost.cpp
)

add_library(testclass SHARED ${SRCS})

target_link_libraries(testclass ${Boost_LIBRARIES} ${QT_QTCORE_LIBRARY})

now trying to import the resulting library results in the following error:

Python 2.7.2 (default, Jun 27 2011, 14:59:25) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import libtestclass
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: ./libtestclass.so: undefined symbol: _ZN6QColor10invalidateEv

Interestingly, some qt classes are not problematic. Without the function c() it works fine (no problem with the QVector). What can I do to make this work? I do not intend to use any functions with qt stuff in python, but I would like to use qt in the c++ only part of the library.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:49:14+00:00Added an answer on May 23, 2026 at 5:49 pm

    You need QtGui for QColor, not just QtCore.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a library written in C that I would like to use in
I have written an application that use a third party library. I have then
I have written a static library to re-use some code between iOS projects, let's
I have a class library with some extension methods written in C# and an
I have a common comms library that i have written to communicate with our
In the library, right-click on a movieclip that you have written an ActionScript class
I'm trying to use some library code written in scala from a java program.
I have a class library that I have written in C#.net. I want to
I have written a custom dialog (form) that I can use in a C#
I have written some JNI hooks into a C++ library and created some DLL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.