我想将Python解释器3.4嵌入到Qt 5.2.1应用程序(64位)中.但是我有构建问题,我的意思是当我在main.cpp中包含Python头时它编译得很好.
#include <python.h>
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
Run Code Online (Sandbox Code Playgroud)
但是当我把它放在其他地方时(在Qt标题之后)
//
// embedpytest.cpp
//
#include <QLibrary>
#include <python.h>
EmbedPyTest::EmbedPyTest()
{
}
Run Code Online (Sandbox Code Playgroud)
我得到编译错误:
C:\Python34\include\object.h:435: error: C2059: syntax error : ';'
C:\Python34\include\object.h:435: error: C2238: unexpected token(s) preceding ';'
Run Code Online (Sandbox Code Playgroud)

这与此问题非常相似,但解决方案无效
谁知道如何解决这个问题?或建议一些干净的解决方法,以便python.h和Qt5能够幸福地生活在一起吗?
如果QString是本地的,用QString发出信号的正确方法是什么?我的意思是我在wigdetA中具有这样的功能
void wigdetA::something()
{
//
//e.g
//
QTreeWidgetItem *it = this->treeWidget->currentItem();
if (it == 0)
return;
QString s = it->text(1);
emit passToMainWindow(s);
}
Run Code Online (Sandbox Code Playgroud)
我应该像这样创建连接(只是const QString):
connect(wigdetA, SIGNAL(passToMainWindow(const QString)), this, SLOT(passToMainWindow(const QString)));
Run Code Online (Sandbox Code Playgroud)
或者我可以使用const reference
connect(wigdetA, SIGNAL(passToMainWindow(const QString&)), this, SLOT(passToMainWindow(const QString&)));
Run Code Online (Sandbox Code Playgroud)
两种方法都可以,但是我第二个const&会使应用程序崩溃,因为QString是本地的,并且在退出something()函数时会销毁它。
还是我想念什么?
任何人都知道如何在msvc2010下编译这个示例代码?(据说在海湾合作委员会下编制)
class cmdLine;
struct cmdList
{
const char *c;
const char *s;
const char *h;
void (cmdLine::*cmdFuncPtr)();
};
class cmdLine
{
public:
cmdLine();
static cmdList myCmdList[];
void test();
};
cmdLine::cmdLine()
{
}
void cmdLine::test()
{
}
cmdList cmdLine::myCmdList[] =
{
{"xxx", "yyy", "zzzzz", &cmdLine::test},
{"aaa", "bbb", "ccc", 0}
};
int _tmain(int argc, _TCHAR* argv[])
{
cmdLine c;
(c.myCmdList[0].*cmdFuncPtr) (); //error (why?)
}
Run Code Online (Sandbox Code Playgroud)
我得到错误C2065:'cmdFuncPtr':未声明的标识符,不知道什么是错的?
我想创建 tkinter 网格布局 5 帧。在替换 Frame 内容之前,它看起来是我想要的样子。
self.Frame1 = tk.Frame(self.parent, bg="grey")
Run Code Online (Sandbox Code Playgroud)
和
self.Frame1 = LeftUpperWindow(self.parent)
Run Code Online (Sandbox Code Playgroud)
当我最大化窗口时,我看到 LeftUpperWindow 框架中的所有内容都乱七八糟,布局不正确。一张图值一千字 所以我有这个
并且想要这个
import sys
import os
import Tkinter as tk
import ttk as ttk
class LeftUpperWindow(tk.Frame):
def __init__(self, master=None):
self.parent = master
tk.Frame.__init__(self, self.parent, bg='#ffffff', borderwidth=1, relief="sunken")
self.__create_layout()
def __create_layout(self):
self.parent.grid()
for r in range(3):
self.parent.rowconfigure(r, weight=1)
for c in range(2):
self.parent.columnconfigure(c, weight=1)
self.editArea = tk.Text(self.parent, wrap=tk.NONE, undo=True,
relief=tk.SUNKEN, borderwidth=5, highlightthickness=0, insertbackground="white")
self.editArea.config(font=('courier', 10, 'normal'))
self.editArea.configure(bg="black", fg="white")
self.editArea.grid(row=0, column=0, sticky=(tk.N, tk.S, tk.W, …Run Code Online (Sandbox Code Playgroud)