我有一个表列消息列ID(主键,自动增量)和内容(文本).
我有一个表用户名列有用户名(主键,文本)和哈希.
一个发件人(用户)向许多收件人(用户)发送邮件,收件人(用户)可以收到许多邮件.
我创建了一个包含两列的表Messages_Recipients:MessageID(引用Messages表的ID列和Recipient(引用Users表中的用户名列).此表表示收件人和邮件之间的多对多关系.
所以,我的问题是这个.在将新消息存储在数据库中之后,将创建新消息的ID.但是,我如何保存对刚刚添加的MessageRow的引用以便检索这个新的MessageID?
我总是可以在数据库中搜索最后添加的行,但是这可能会在多线程环境中返回一个不同的行?
编辑:据我所知,SQLite你可以使用SELECT last_insert_rowid()
.但是如何从ADO.Net中调用此声明?
我的持久性代码(messages和messagesRecipients是DataTables):
public void Persist(Message message)
{
pm_databaseDataSet.MessagesRow messagerow;
messagerow=messages.AddMessagesRow(message.Sender,
message.TimeSent.ToFileTime(),
message.Content,
message.TimeCreated.ToFileTime());
UpdateMessages();
var x = messagerow;//I hoped the messagerow would hold a
//reference to the new row in the Messages table, but it does not.
foreach (var recipient in message.Recipients)
{
var row = messagesRecipients.NewMessages_RecipientsRow();
row.Recipient = recipient;
//row.MessageID= How do I find this??
messagesRecipients.AddMessages_RecipientsRow(row);
UpdateMessagesRecipients();//method not shown
}
}
private void UpdateMessages()
{
messagesAdapter.Update(messages);
messagesAdapter.Fill(messages);
}
Run Code Online (Sandbox Code Playgroud) 我试图通过Cmake构建并运行Qt的非常简单和基本的示例,删除.pro文件.以下是Qt项目的代码(自动生成的Qt项目的目录结构是
Cmake (my project name)
??? headers
? ??? mainwindow.h
??? sources
? ??? main.cpp
? ??? mainwindow.cpp
??? forms
??? mainwindow.ui
Run Code Online (Sandbox Code Playgroud)
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
Run Code Online (Sandbox Code Playgroud)
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
Run Code Online (Sandbox Code Playgroud)
main.cpp中
#include "mainwindow.h"
#include <QApplication> …
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个JavaScript函数,它将打开我的扩展名,就像点击扩展图标一样.我知道如何在新标签中打开我的扩展程序:
var url = "chrome-extension://kelodmiboakdjlbcdfoceeiafckgojel/login.html";
window.open(url);
Run Code Online (Sandbox Code Playgroud)
但是我想在浏览器的右上角打开一个弹出窗口,就像点击扩展图标一样.
我想概括以下模式:
template<class A1, class A2, class A3>
class Foo {
protected:
template<class T>
void foo(const T& t) {...do stuff...}
public:
void bar(const A1& a) { foo(a); }
void bar(const A2& a) { foo(a); }
void bar(const A3& a) { foo(a); }
};
Run Code Online (Sandbox Code Playgroud)
上述方法不会随着一些不断增加的论点而扩展.所以,我想做:
template<class As...>
class Foo {
protected:
template<class T>
void foo(const t& a) {...do stuff...}
public:
for each type A in As declare:
void bar(const A& a) { foo(a); }
};
Run Code Online (Sandbox Code Playgroud)
有办法吗?
我在.pro文件中有以下内容,我有文件,#include "headerhere".
例如: #include "StdAfx.h"
.但是我得到了一个
错误无法打开包含文件:'StdAfx.h':没有这样的文件或目录.
我是否使用#include "StdAfx.h"
或得到相同的错误#include "Shared/StdAfx.h"
.这非常令人沮丧,除非Qt开始识别我的标题,否则我无法做任何实际的工作.我在网上找不到解决方案.到底是怎么回事?
.pro文件有:
HEADERS += ibproject.h \
Shared/StdAfx.h \
Shared/TwsSocketClientErrors.h \
Shared/TagValue.h \
Shared/shared_ptr.h \
Shared/ScannerSubscription.h \
Shared/OrderState.h \
Shared/Order.h \
Shared/IBString.h \
Shared/HScrollListBox.h \
Shared/Execution.h \
Shared/EWrapper.h \
Shared/EClientSocketBaseImpl.h \
Shared/EClientSocketBase.h \
Shared/EClient.h \
Shared/Contract.h \
Shared/CommonDefs.h \
Shared/CommissionReport.h \
SocketClient/src/EClientSocket.h
ewrappersubclass.h
INCLUDEPATH += $$PWD/SocketClient
DEPENDPATH += $$PWD/SocketClient
Run Code Online (Sandbox Code Playgroud)
编辑:为什么我得到了投票?这是我遇到的合法问题
我按照Qt提供的Spin Box Delegate教程,尝试实现自己的QItemDelegate
.它将用于指定a QComboBox
来表示QTableView
单元格中的数据,但它不起作用.
我最大的问题是我不知道什么时候QItemDelegate
会被利用.
何时itemModel->setData()
使用或何时使用itemModel->setItem()
.我怀疑setItem()
是因为我重新实现了QItemDelegate
(强调"项目"),但教程使用setData()
并且它工作正常.
我知道,如果指定QItemDelegate
不起作用,它使用默认值,但我现在怎么说我指定的那个不起作用?
什么时候我应该怀疑QTableView
使用我的代表.我想指定每个单元格使用哪些代理.这是可能的还是QTableView
唯一使用一个代表?
如何将我指定的项目来填充QComboBox
一旦获得通过所显示的QTableView
?
我QItemDelegate
在这里实现:
QComboBox
位于mainwindow.cpp中的注释"Enabled"下面.qcomboboxitemdelegate.h
#ifndef QCOMBOBOXITEMDELEGATE_H
#define QCOMBOBOXITEMDELEGATE_H
#include <QItemDelegate>
#include <QComboBox>
class QComboBoxItemDelegate : public QItemDelegate
{
Q_OBJECT
public:
explicit QComboBoxItemDelegate(QObject *parent = 0);
QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index);
void setEditorData(QWidget *editor, const QModelIndex &index);
void …
Run Code Online (Sandbox Code Playgroud) 在C++ 11中,没有explicit
关键字的构造函数可用于将参数列表隐式转换为其类.例如:
class Date{
private:
int d, m, y;
public:
Date(int _d, int _m=0, int _y=0) : m(_m), d(_d), y(_y) {}
friend bool operator==(const Date &x, const Date &y) {return x.d==y.d;}
};
int main()
{
Date x = {1,2,3}; // no error; using converting constructor
x == 1; // no error; converting constructor turns int into Date object
x == {1,2,3}; // error
}
Run Code Online (Sandbox Code Playgroud)
因为x == {1,2,3}
,我收到以下错误:
explicit.cc:16:10: error: expected primary-expression before ‘{’ token
x=={1,2,3};
^ …
Run Code Online (Sandbox Code Playgroud) 如果共享指针要被复制到成员变量,是否应该通过引用或值作为参数传递给类?
复制共享指针将增加参考计数,我不想做任何不必要的副本,因此ref计数增量.将共享指针作为参考传递解决这个问题?我认为确实如此,但是还有其他问题吗?
价值传递:
class Boo {
public:
Boo() { }
};
class Foo {
public:
Foo(std::shared_ptr<Boo> boo)
: m_Boo(boo) {}
private:
std::shared_ptr<Boo> m_Boo;
};
int main() {
std::shared_ptr<Boo> boo = std::make_shared<Boo>();
Foo foo(boo);
}
Run Code Online (Sandbox Code Playgroud)
通过参考:
class Boo {
public:
Boo() { }
};
class Foo {
public:
Foo(std::shared_ptr<Boo>& boo)
: m_Boo(boo) {}
private:
std::shared_ptr<Boo> m_Boo;
};
int main() {
std::shared_ptr<Boo> boo = std::make_shared<Boo>();
Foo foo(boo);
}
Run Code Online (Sandbox Code Playgroud) 我是Android开发环境的新手,我需要将我的应用程序连接到firebase但是我收到此错误
无法解决:firebase-auth-15.0.0
此错误显示在语句中:
implementation 'com.google.firebase:firebase-auth:16.0.1:15.0.0'
Run Code Online (Sandbox Code Playgroud)
此语句包含两个版本的详细信息,我认为错误是由此引起的,但此特定语句由firebase本身提供.看图像:
我试图将上述声明改为
implementation 'com.google.firebase:firebase-auth:16.0.3'
Run Code Online (Sandbox Code Playgroud)
但是后来firebase依赖没有建立起来.
我想将NULL传递给以下函数的第4个参数:
bool CCMenuItemToggle::initWithTarget(CCObject* target, SEL_MenuHandler selector, CCMenuItem* item, **va_list args**);
Run Code Online (Sandbox Code Playgroud)
像这样:
CCMenuItemToggle::initWithTarget(this, menu_selector(GOSound::toggleButtonCallback), NULL, NULL);
Run Code Online (Sandbox Code Playgroud)
我在XCode(clang3.1)中构建它时没关系.但是当我将代码移植到android ndk(g ++ 4.7)时,它无法编译:
没有可行的从'int'转换为'va_list'(又名'__builtin_va_list')
我该怎么处理呢?
c++ ×7
qt ×3
c++11 ×2
android ×1
android-ndk ×1
constructor ×1
database ×1
firebase ×1
g++ ×1
primary-key ×1
qcombobox ×1
qtableview ×1
shared-ptr ×1
sqlite ×1
templates ×1