我想type::base用一些常用的功能和流畅的接口构建一个基类(抽象)类(让我们称它),我面临的问题是所有这些方法的返回类型
class base {
public:
base();
virtual ~base();
base& with_foo();
base& with_bar();
protected:
// whatever...
};
Run Code Online (Sandbox Code Playgroud)
现在我可以制作子类型,例如:
class my_type : public base {
public:
myType();
// more methods...
};
Run Code Online (Sandbox Code Playgroud)
使用这样的子类型时出现问题:
my_type build_my_type()
{
return my_type().with_foo().with_bar();
}
Run Code Online (Sandbox Code Playgroud)
这将无法编译,因为我们正在返回base而不是my_type.
我知道我可以:
my_type build_my_type()
{
my_type ret;
ret.with_foo().with_bar();
return ret;
}
Run Code Online (Sandbox Code Playgroud)
但我在想如何实现它,我没有找到任何有效的想法,一些建议?
我正在尝试将应用程序部署到Apache Felix.这是一个gwt应用程序,但我一直在简化问题,直到一个hello world html文件,所以我的问题是在war文件中部署任何类型的Web应用程序.我还尝试在Apache Karaf中部署生成的战争,并且它们没有任何问题(一旦你安装了功能战争).
所以,现在我有这个:
blaxter@duffman:~/devel/webapp $ tree
.
??? pom.xml
??? src
??? main
??? resources
??? webapp
??? foobar.html
??? WEB-INF
??? web.xml
Run Code Online (Sandbox Code Playgroud)
pom.xml非常简单,有趣的部分与felix插件有关,但对于这场没有任何编译代码的战争它并不重要......
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>webapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>webapp Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>webapp</finalName>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
<configuration>
<supportedProjectTypes>
<supportedProjectType>jar</supportedProjectType>
<supportedProjectType>bundle</supportedProjectType>
<supportedProjectType>war</supportedProjectType>
</supportedProjectTypes>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Version>${project.version}</Bundle-Version>
<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
<Embed-Directory>WEB-INF/lib</Embed-Directory>
<Embed-Transitive>true</Embed-Transitive> …Run Code Online (Sandbox Code Playgroud) 我正在使用pyside,但(我认为)是一个通用的Qt问题.
我知道QThread实现调用._exec()方法,所以我们应该在启动的QThread上有一个事件循环.这样我们就可以在那个线程上使用QTimer(我已经完成了这个并且它完美地工作).我的问题是当QWaitCondition也被使用时,我想要一个带有无限循环的"消费者"线程等待在QWaitCondition上通知(来自生产者).我遇到的问题是,使用此设计我不能在消费者线程中使用QTimer.
这是我试图解释的场景的片段:
from PySide import QtGui
from PySide import QtCore
import sys
class MainWindow(QtGui.QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.button = QtGui.QPushButton(self)
self.button.setText("Periodical")
self.button.clicked.connect(self.periodical_call)
self.thread = QtCore.QThread()
self.worker = Worker()
self.worker.moveToThread(self.thread)
self.thread.started.connect(self.worker.loop)
self.thread.start()
def closeEvent(self, x):
self.worker.stop()
self.thread.quit()
self.thread.wait()
def periodical_call(self):
self.worker.do_stuff("main window") # this works
self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.do_stuff) # this also works
self.timer.start(2000)
def do_stuff(self):
self.worker.do_stuff("timer main window")
class Worker(QtCore.QObject):
def do_stuff_timer(self):
do_stuff("timer worker")
def do_stuff(self, origin):
self.origin = origin
self.wait.wakeOne()
def stop(self):
self._exit = True
self.wait.wakeAll()
def …Run Code Online (Sandbox Code Playgroud) apache-felix ×1
c++ ×1
inheritance ×1
osgi ×1
pax ×1
pax-runner ×1
pyside ×1
python ×1
qt ×1
qthread ×1
qtimer ×1
war ×1